Skip to content

Commit

Permalink
stat_opt: check extra strlen call
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 20, 2014
1 parent d12c24d commit 0539cc0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0539cc0

Please sign in to comment.