summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-18 15:51:17 -0400
committerJunio C Hamano <gitster@pobox.com>2014-06-20 10:45:19 -0700
commit0539cc0038ff3411da1fea342b7d6615643bff5b (patch)
treed8be8b442d56b28de63051611c99821f2a58eab2 /diff.c
parentd12c24d2a96f8f9aeb100b800d8fb217f28a6a2a (diff)
downloadgit-0539cc0038ff3411da1fea342b7d6615643bff5b.tar.gz
stat_opt: check extra strlen call
As in earlier commits, the diff option parser uses starts_with to find that an argument starts with "--stat-", and then adds strlen("stat-") to find the rest of the option. However, in this case the starts_with and the strlen are separated across functions, making it easy to call the latter without the former. Let's use skip_prefix instead of raw pointer arithmetic to catch such a case. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 2378ae49c6..06bdfb8ae5 100644
--- a/diff.c
+++ b/diff.c
@@ -3422,7 +3422,8 @@ static int stat_opt(struct diff_options *options, const char **av)
int count = options->stat_count;
int argcount = 1;
- arg += strlen("--stat");
+ if (!skip_prefix(arg, "--stat", &arg))
+ die("BUG: stat option does not begin with --stat: %s", arg);
end = (char *)arg;
switch (*arg) {