summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2018-09-25 19:24:36 -0600
committerJens Axboe <axboe@kernel.dk>2018-09-25 19:24:36 -0600
commit5d2788d5b7987f81e705cd1656017ab36254b4f8 (patch)
tree04415f34b7f5a6ec2a3b6b0ba438684d8f97d8e1 /parse.c
parenta69c9b57ddcff0cfaa481578ecbc4630b27b971f (diff)
downloadfio-5d2788d5b7987f81e705cd1656017ab36254b4f8.tar.gz
fio-5d2788d5b7987f81e705cd1656017ab36254b4f8.tar.bz2
parse: fix min/max val checking for FIO_OPT_INT
We compare an unsigned long long to an int max/min value, this is going to break for negative numbers, for instance. Fixes a case where flow=-1 doesn't work properly because of that. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index 196de155..9a20d0c7 100644
--- a/parse.c
+++ b/parse.c
@@ -506,6 +506,36 @@ static const char *opt_type_name(const struct fio_option *o)
return "OPT_UNKNOWN?";
}
+static bool val_too_large(const struct fio_option *o, unsigned long long val,
+ bool is_uint)
+{
+ if (!o->maxval)
+ return false;
+
+ if (is_uint) {
+ unsigned int uint_val = val;
+
+ return uint_val > o->maxval;
+ }
+
+ return val > o->maxval;
+}
+
+static bool val_too_small(const struct fio_option *o, unsigned long long val,
+ bool is_uint)
+{
+ if (!o->minval)
+ return false;
+
+ if (is_uint) {
+ unsigned int uint_val = val;
+
+ return uint_val < o->minval;
+ }
+
+ return val < o->minval;
+}
+
static int __handle_option(const struct fio_option *o, const char *ptr,
void *data, int first, int more, int curr)
{
@@ -595,12 +625,12 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
return 1;
}
- if (o->maxval && ull > o->maxval) {
+ if (val_too_large(o, ull, o->type == FIO_OPT_INT)) {
log_err("%s: max value out of range: %llu"
" (%llu max)\n", o->name, ull, o->maxval);
return 1;
}
- if (o->minval && ull < o->minval) {
+ if (val_too_small(o, ull, o->type == FIO_OPT_INT)) {
log_err("%s: min value out of range: %lld"
" (%d min)\n", o->name, ull, o->minval);
return 1;