Skip to content

Commit 0539cc0

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d12c24d commit 0539cc0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,8 @@ static int stat_opt(struct diff_options *options, const char **av)
34223422
int count = options->stat_count;
34233423
int argcount = 1;
34243424

3425-
arg += strlen("--stat");
3425+
if (!skip_prefix(arg, "--stat", &arg))
3426+
die("BUG: stat option does not begin with --stat: %s", arg);
34263427
end = (char *)arg;
34273428

34283429
switch (*arg) {

0 commit comments

Comments
 (0)