Fix parser bug with ranges
The change to allow -/+ for values broke ranges.
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
diff --git a/options.c b/options.c
index 74c24d0..06ac659 100644
--- a/options.c
+++ b/options.c
@@ -102,7 +102,7 @@
} else
perc = -1;
- if (str_to_decimal(fname, &val, 1, td)) {
+ if (str_to_decimal(fname, &val, 1, 1, td)) {
log_err("fio: bssplit conversion failed\n");
free(td->o.bssplit);
return 1;
@@ -213,7 +213,7 @@
else {
long long val;
- if (str_to_decimal(nr, &val, 1, td)) {
+ if (str_to_decimal(nr, &val, 1, 0, td)) {
log_err("fio: rw postfix parsing failed\n");
free(nr);
return 1;
diff --git a/parse.c b/parse.c
index 2dee446..55de4f0 100644
--- a/parse.c
+++ b/parse.c
@@ -184,7 +184,7 @@
}
static unsigned long long get_mult_bytes(const char *str, int len, void *data,
- int *percent)
+ int *percent, int is_range)
{
const char *p = str;
@@ -195,7 +195,9 @@
* Go forward until we hit a non-digit, or +/- sign
*/
while ((p - str) <= len) {
- if (!isdigit((int) *p) && (*p != '+') && (*p != '-'))
+ if (!isdigit((int) *p) && (*p != '+'))
+ break;
+ if (!is_range && (*p != '-'))
break;
p++;
}
@@ -217,7 +219,7 @@
/*
* convert string into decimal value, noting any size suffix
*/
-int str_to_decimal(const char *str, long long *val, int kilo, void *data)
+int str_to_decimal(const char *str, long long *val, int kilo, int is_range, void *data)
{
int len, base;
@@ -238,7 +240,7 @@
unsigned long long mult;
int perc = 0;
- mult = get_mult_bytes(str, len, data, &perc);
+ mult = get_mult_bytes(str, len, data, &perc, is_range);
if (perc)
*val = -1ULL - *val;
else
@@ -249,14 +251,14 @@
return 0;
}
-static int check_str_bytes(const char *p, long long *val, void *data)
+static int check_str_bytes(const char *p, long long *val, int is_range, void *data)
{
- return str_to_decimal(p, val, 1, data);
+ return str_to_decimal(p, val, 1, is_range, data);
}
static int check_str_time(const char *p, long long *val)
{
- return str_to_decimal(p, val, 0, NULL);
+ return str_to_decimal(p, val, 0, 0, NULL);
}
void strip_blank_front(char **p)
@@ -293,7 +295,7 @@
{
long long __val;
- if (!str_to_decimal(str, &__val, 1, data)) {
+ if (!str_to_decimal(str, &__val, 1, 1, data)) {
*val = __val;
return 0;
}
@@ -402,7 +404,7 @@
if (is_time)
ret = check_str_time(ptr, &ull);
else
- ret = check_str_bytes(ptr, &ull, data);
+ ret = check_str_bytes(ptr, &ull, 0, data);
if (ret)
break;
diff --git a/parse.h b/parse.h
index f2265a4..f1f3927 100644
--- a/parse.h
+++ b/parse.h
@@ -75,7 +75,7 @@
extern void strip_blank_front(char **);
extern void strip_blank_end(char *);
-extern int str_to_decimal(const char *, long long *, int, void *);
+extern int str_to_decimal(const char *, long long *, int, int, void *);
/*
* Handlers for the options