[PATCH 07/14] handle_revision_opt(): use convert_ui() when handling "--abbrev="
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Mar 17, 2015, 16:00 UTC
- Message-ID
- <1426608016-2978-8-git-send-email-mhagger@alum.mit.edu>
- In-Reply-To
- <1426608016-2978-1-git-send-email-mhagger@alum.mit.edu>
This adds error checking, where previously there was none. It also disallows '+' and '-', leading whitespace, and trailing junk.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> --- revision.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/revision.c b/revision.c index 4908e66..a6f7c2e 100644 --- a/revision.c +++ b/revision.c @@ -1963,7 +1963,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--abbrev")) { revs->abbrev = DEFAULT_ABBREV; } else if (skip_prefix(arg, "--abbrev=", &arg)) { - revs->abbrev = strtoul(arg, NULL, 10); + if (convert_ui(arg, 10, &revs->abbrev)) + die("--abbrev requires a non-negative integer argument"); if (revs->abbrev < MINIMUM_ABBREV) revs->abbrev = MINIMUM_ABBREV; else if (revs->abbrev > 40)
-- 2.1.4