Add thread_segments as needed
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 84d112dceb9efc3d433e13b39693aee3de46a6e1..f4cefcf6243edbd911cb4f274611912c440a5f07 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -373,12 +373,16 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data,
 #endif
 
        if (rc == 1) {
+               char *endptr;
+
                if (strstr(str, "0x") || strstr(str, "0X"))
                        base = 16;
                else
                        base = 10;
 
-               *val = strtoll(str, NULL, base);
+               *val = strtoll(str, &endptr, base);
+               if (*val == 0 && endptr == str)
+                       return 1;
                if (*val == LONG_MAX && errno == ERANGE)
                        return 1;
        }
@@ -512,8 +516,11 @@ static bool val_too_large(const struct fio_option *o, unsigned long long val,
        if (!o->maxval)
                return false;
 
-       if (is_uint)
+       if (is_uint) {
+               if ((int) val < 0)
+                       return (int) val > (int) o->maxval;
                return (unsigned int) val > o->maxval;
+       }
 
        return val > o->maxval;
 }
@@ -589,7 +596,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
        }
        case FIO_OPT_STR_VAL_TIME:
                is_time = 1;
-               /* fall through */
+               fallthrough;
        case FIO_OPT_ULL:
        case FIO_OPT_INT:
        case FIO_OPT_STR_VAL: {
@@ -599,8 +606,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
                if (!is_time && o->is_time)
                        is_time = o->is_time;
 
-               tmp[sizeof(tmp) - 1] = '\0';
-               strncpy(tmp, ptr, sizeof(tmp) - 1);
+               snprintf(tmp, sizeof(tmp), "%s", ptr);
                p = strchr(tmp, ',');
                if (p)
                        *p = '\0';
@@ -826,8 +832,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
                char tmp[128];
                char *p1, *p2;
 
-               tmp[sizeof(tmp) - 1] = '\0';
-               strncpy(tmp, ptr, sizeof(tmp) - 1);
+               snprintf(tmp, sizeof(tmp), "%s", ptr);
 
                /* Handle bsrange with separate read,write values: */
                p1 = strchr(tmp, ',');
@@ -936,7 +941,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
        }
        case FIO_OPT_DEPRECATED:
                ret = 1;
-               /* fall through */
+               fallthrough;
        case FIO_OPT_SOFT_DEPRECATED:
                log_info("Option %s is deprecated\n", o->name);
                break;
@@ -1043,7 +1048,20 @@ struct fio_option *find_option(struct fio_option *options, const char *opt)
 const struct fio_option *
 find_option_c(const struct fio_option *options, const char *opt)
 {
-       return find_option((struct fio_option *)options, opt);
+       const struct fio_option *o;
+
+       for (o = &options[0]; o->name; o++) {
+               if (!o_match(o, opt))
+                       continue;
+               if (o->type == FIO_OPT_UNSUPPORTED) {
+                       log_err("Option <%s>: %s\n", o->name, o->help);
+                       continue;
+               }
+
+               return o;
+       }
+
+       return NULL;
 }
 
 static const struct fio_option *