Re: [PATCH 14/14] diff_opt_parse(): use convert_i() when handling --abbrev=<num>
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 19, 2015, 06:37 UTC
- Message-ID
- <xmqqsid1jxwt.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1426608016-2978-15-git-send-email-mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 20 quoted lines
> die() with an error message if the argument is not a non-negative
> integer. This change tightens up parsing: '+' and '-', leading
> whitespace, and trailing junk are all disallowed now.
>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
> diff.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index be389ae..1cc5428 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -3830,7 +3830,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
> else if (!strcmp(arg, "--abbrev"))
> options->abbrev = DEFAULT_ABBREV;
> else if (skip_prefix(arg, "--abbrev=", &arg)) {
> - options->abbrev = strtoul(arg, NULL, 10);
> + if (convert_i(arg, 10, &options->abbrev))
> + die("--abbrev requires an integer argument");Everybody leading up to this step said "a non-negative integer", but this one is different?
> if (options->abbrev < MINIMUM_ABBREV) > options->abbrev = MINIMUM_ABBREV; > else if (40 < options->abbrev)