Better parser fix
authorJens Axboe <jaxboe@fusionio.com>
Wed, 7 Sep 2011 20:11:00 +0000 (22:11 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Wed, 7 Sep 2011 20:11:00 +0000 (22:11 +0200)
The previous one broke all postfixes for ranges, that wasn't
very nice. This one allows the proper postfix and +/- as well,
as long as the latter is seen before a digit.

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
parse.c

diff --git a/parse.c b/parse.c
index 2dee446d7a8a2ad0614e37c4a5bd09796f5e296d..f52139f5cb0eff2cf85ca10b99db743b567ef174 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -187,6 +187,7 @@ static unsigned long long get_mult_bytes(const char *str, int len, void *data,
                                         int *percent)
 {
        const char *p = str;
+       int digit_seen = 0;
 
        if (len < 2)
                return __get_mult_bytes(str, data, percent);
@@ -195,8 +196,10 @@ static unsigned long long get_mult_bytes(const char *str, int len, void *data,
          * Go forward until we hit a non-digit, or +/- sign
          */
        while ((p - str) <= len) {
-               if (!isdigit((int) *p) && (*p != '+') && (*p != '-'))
+               if (!isdigit((int) *p) &&
+                   (((*p != '+') && (*p != '-')) || digit_seen))
                        break;
+               digit_seen |= isdigit(*p);
                p++;
        }