revision.c: stricter parsing of '--early-output'

The parsing of '--early-output' with or without its optional integer
argument allowed bogus options like '--early-output-foobarbaz' to slip
through and be ignored.

Fix it by parsing '--early-output' in the same way as other options
with an optional argument are parsed.  Furthermore, use strtoul_ui()
to parse the optional integer argument and to refuse negative numbers.

While at it, use skip_prefix() instead of starts_with() and magic
numbers.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
SZEDER Gábor 2017-06-09 20:17:31 +02:00 committed by Junio C Hamano
parent 9ada7aee19
commit dffc651ed1

View File

@ -1750,16 +1750,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
} else if (!strcmp(arg, "--author-date-order")) { } else if (!strcmp(arg, "--author-date-order")) {
revs->sort_order = REV_SORT_BY_AUTHOR_DATE; revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
revs->topo_order = 1; revs->topo_order = 1;
} else if (starts_with(arg, "--early-output")) { } else if (!strcmp(arg, "--early-output")) {
int count = 100; revs->early_output = 100;
switch (arg[14]) { revs->topo_order = 1;
case '=': } else if (skip_prefix(arg, "--early-output=", &optarg)) {
count = atoi(arg+15); if (strtoul_ui(optarg, 10, &revs->early_output) < 0)
/* Fallthrough */ die("'%s': not a non-negative integer", optarg);
case 0: revs->topo_order = 1;
revs->topo_order = 1;
revs->early_output = count;
}
} else if (!strcmp(arg, "--parents")) { } else if (!strcmp(arg, "--parents")) {
revs->rewrite_parents = 1; revs->rewrite_parents = 1;
revs->print_parents = 1; revs->print_parents = 1;