X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=parse.c;h=97ea4aab47961115a97a16cbbe6b0034e429027d;hb=8eb016d3727522d580d4dd463aefef58b7ecdb00;hp=e9eb73852dbccbeb630b415db7220678054553ad;hpb=1a1137d9ba2603e295aaac579777ab0d3524faa6;p=fio.git diff --git a/parse.c b/parse.c index e9eb7385..97ea4aab 100644 --- 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'; @@ -309,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; + int ret = 0, is_time = 0; dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name, o->type, ptr); @@ -357,14 +358,17 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data, ret = fn(data, ptr); break; } - case FIO_OPT_STR_VAL_TIME: { - fio_opt_str_val_fn *fn; - - ret = check_str_time(ptr, &ull); + case FIO_OPT_STR_VAL_TIME: + is_time = 1; case FIO_OPT_INT: - case FIO_OPT_STR_VAL: + case FIO_OPT_STR_VAL: { + fio_opt_str_val_fn *fn = o->cb; + + if (is_time) + ret = check_str_time(ptr, &ull); + else + ret = check_str_bytes(ptr, &ull, data); - ret = check_str_bytes(ptr, &ull, data); if (ret) break; @@ -379,7 +383,6 @@ 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 {