[PATCH 12/14] opt_arg(): simplify pointer handling
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Mar 17, 2015, 16:00 UTC
- Message-ID
- <1426608016-2978-13-git-send-email-mhagger@alum.mit.edu>
- In-Reply-To
- <1426608016-2978-1-git-send-email-mhagger@alum.mit.edu>
Increment "arg" when a character is consumed, not just before consuming the next character.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> --- diff.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c index 03cdabf..bc1e3c3 100644 --- a/diff.c +++ b/diff.c @@ -3358,14 +3358,13 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va char c, *eq; int len; - if (*arg != '-') + if (*arg++ != '-') return 0; - c = *++arg; + c = *arg++; if (!c) return 0; if (c == arg_short) { - c = *++arg; - if (!c) + if (!*arg) return 1; /* optional argument was missing */ if (convert_i(arg, 10, val)) die("The value for -%c must be a non-negative integer", arg_short); @@ -3373,7 +3372,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va } if (c != '-') return 0; - arg++; eq = strchrnul(arg, '='); len = eq - arg; if (!len || strncmp(arg, arg_long, len))
-- 2.1.4