Fix bug in $mb_memory keyword
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index bb138e55f967fbeb6aa09690b79fa4b18092cbb4..97ea4aab47961115a97a16cbbe6b0034e429027d 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -168,20 +168,21 @@ 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--;
-       if (!isalpha(*p))
+        /*
+         * Go forward until we hit a non-digit
+         */
+       while ((p - str) <= len) {
+               if (!isdigit((int) *p))
+                       break;
+               p++;
+       }
+
+       if (!isalpha((int) *p))
                p = NULL;
 
        return __get_mult_bytes(p, data);
@@ -229,7 +230,7 @@ void strip_blank_front(char **p)
 {
        char *s = *p;
 
-       while (isspace(*s))
+       while (isspace((int) *s))
                s++;
 
        *p = s;
@@ -249,7 +250,7 @@ void strip_blank_end(char *p)
                p = s;
 
        s = p + strlen(p);
-       while ((isspace(*s) || iscntrl(*s)) && (s > start))
+       while ((isspace((int) *s) || iscntrl((int) *s)) && (s > start))
                s--;
 
        *(s + 1) = '\0';