X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=parse.c;h=d44d13082c91dd8951cbe0be7edf2c51dd73d7e0;hb=fc2a6f2266bc616f6444fb580053f9ea26e6e563;hp=b0ea3d3a5bae985d14c1a7f71a5bf2198ae45615;hpb=5338f35ddd52203048e2f6262b7254dddc2d8d52;p=fio.git diff --git a/parse.c b/parse.c index b0ea3d3a..d44d1308 100644 --- a/parse.c +++ b/parse.c @@ -162,9 +162,19 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data) if (*val == LONG_MAX && errno == ERANGE) return 1; - if (kilo) - *val *= get_mult_bytes(str[len - 1], data); - else + if (kilo) { + const char *p; + /* + * 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; + if ((*p == 'b' || *p == 'B') && isalpha(*(p - 1))) + --p; + + *val *= get_mult_bytes(*p, data); + } else *val *= get_mult_time(str[len - 1]); return 0; @@ -557,7 +567,7 @@ static int opt_cmp(const void *p1, const void *p2) o1 = get_option(s1, fio_options, &foo); o2 = get_option(s2, fio_options, &foo); - + prio1 = prio2 = 0; if (o1) prio1 = o1->prio; @@ -610,6 +620,11 @@ static char *option_dup_subs(const char *opt) ssize_t nchr = OPT_LEN_MAX; size_t envlen; + if (strlen(in) + 1 > OPT_LEN_MAX) { + fprintf(stderr, "OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX); + return NULL; + } + in[OPT_LEN_MAX] = '\0'; strncpy(in, opt, OPT_LEN_MAX); @@ -649,6 +664,8 @@ int parse_option(const char *opt, struct fio_option *options, void *data) char *post, *tmp; tmp = option_dup_subs(opt); + if (!tmp) + return 1; o = get_option(tmp, options, &post); if (!o) {