Fix parser bug dealing with range options and postfix
authorJens Axboe <jaxboe@fusionio.com>
Sun, 27 Mar 2011 18:55:09 +0000 (20:55 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Sun, 27 Mar 2011 18:55:09 +0000 (20:55 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
parse.c

diff --git a/parse.c b/parse.c
index e9eb73852dbccbeb630b415db7220678054553ad..585fb7e0ecb1c1b6b5dbd7c5bb65fe4a906837f8 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -168,19 +168,20 @@ static unsigned long long __get_mult_bytes(const char *p, void *data)
 
 static unsigned long long get_mult_bytes(const char *str, int len, void *data)
 {
-       const char *p;
+       const char *p = str;
 
        if (len < 2)
                return __get_mult_bytes(str, data);
 
-       /*
-        * if the last char is 'b' or 'B', the user likely used
-        * "1gb" instead of just "1g". If the second to last is also
-        * a letter, adjust.
-        */
-       p = str + len - 1;
-       while (isalpha(*(p - 1)))
-               p--;
+        /*
+         * Go forward until we hit a non-digit
+         */
+       while ((p - str) <= len) {
+               if (!isdigit(*p))
+                       break;
+               p++;
+       }
+
        if (!isalpha(*p))
                p = NULL;