summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-03-17 17:00:12 +0100
committerJunio C Hamano <gitster@pobox.com>2015-03-19 11:03:00 -0700
commit7056f0bcff304aa609641b0c7c23a45021114c04 (patch)
tree2781d38b21005f04aab265904796eebe9723dd2b
parentcb05723c130ca006d8e2242db044dadcf7ab6a9d (diff)
downloadgit-7056f0bcff304aa609641b0c7c23a45021114c04.tar.gz
opt_arg(): use convert_i() in implementation
This shortens the code and avoids the old code's careless truncation from unsigned long to int. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--diff.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/diff.c b/diff.c
index dbaa869eab..130ae65f35 100644
--- a/diff.c
+++ b/diff.c
@@ -3365,16 +3365,10 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
if (c == arg_short) {
c = *++arg;
if (!c)
- return 1;
- if (isdigit(c)) {
- char *end;
- int n = strtoul(arg, &end, 10);
- if (*end)
- return 0;
- *val = n;
- return 1;
- }
- return 0;
+ return 1; /* optional argument was missing */
+ if (convert_i(arg, 10, val))
+ return 0;
+ return 1;
}
if (c != '-')
return 0;
@@ -3383,16 +3377,10 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
len = eq - arg;
if (!len || strncmp(arg, arg_long, len))
return 0;
- if (*eq) {
- int n;
- char *end;
- if (!isdigit(*++eq))
- return 0;
- n = strtoul(eq, &end, 10);
- if (*end)
- return 0;
- *val = n;
- }
+ if (!*eq)
+ return 1; /* '=' and optional argument were missing */
+ if (convert_i(eq + 1, 10, val))
+ return 0;
return 1;
}