Fix parser bug dealing with range options and postfix
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index db2f5a42f85aa68b5c7e768f0dee5f2be14cef2a..585fb7e0ecb1c1b6b5dbd7c5bb65fe4a906837f8 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -79,6 +79,7 @@ static void show_option_help(struct fio_option *o, FILE *out)
        const char *typehelp[] = {
                "invalid",
                "string (opt=bla)",
+               "string (opt=bla)",
                "string with possible k/m/g postfix (opt=4k)",
                "string with time postfix (opt=10s)",
                "string (opt=bla)",
@@ -167,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;
 
@@ -308,7 +310,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
        long long ull, *ullp;
        long ul1, ul2;
        char **cp;
-       int ret = 0, is_time = 0;
+       int ret = 0;
 
        dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
                                                        o->type, ptr);
@@ -356,17 +358,14 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                        ret = fn(data, ptr);
                break;
        }
-       case FIO_OPT_STR_VAL_TIME:
-               is_time = 1;
-       case FIO_OPT_INT:
-       case FIO_OPT_STR_VAL: {
-               fio_opt_str_val_fn *fn = o->cb;
+       case FIO_OPT_STR_VAL_TIME: {
+               fio_opt_str_val_fn *fn;
 
-               if (is_time)
-                       ret = check_str_time(ptr, &ull);
-               else
-                       ret = check_str_bytes(ptr, &ull, data);
+               ret = check_str_time(ptr, &ull);
+       case FIO_OPT_INT:
+       case FIO_OPT_STR_VAL:
 
+               ret = check_str_bytes(ptr, &ull, data);
                if (ret)
                        break;
 
@@ -381,6 +380,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                        return 1;
                }
 
+               fn = o->cb;
                if (fn)
                        ret = fn(data, &ull);
                else {