projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix bug in parser with postfix and truncated direction values
[fio.git]
/
parse.c
diff --git
a/parse.c
b/parse.c
index 8a2e6f215f0ba1f3df53abb2e3e9774a7180af17..c2d744b3088f5a4d74f1e94e9ea9631f9b2859e4 100644
(file)
--- a/
parse.c
+++ b/
parse.c
@@
-112,13
+112,18
@@
static unsigned long get_mult_bytes(char c)
*/
int str_to_decimal(const char *str, long long *val, int kilo)
{
*/
int str_to_decimal(const char *str, long long *val, int kilo)
{
- int len;
+ int len
, base
;
len = strlen(str);
if (!len)
return 1;
len = strlen(str);
if (!len)
return 1;
- *val = strtoll(str, NULL, 10);
+ if (strstr(str, "0x") || strstr(str, "0X"))
+ base = 16;
+ else
+ base = 10;
+
+ *val = strtoll(str, NULL, base);
if (*val == LONG_MAX && errno == ERANGE)
return 1;
if (*val == LONG_MAX && errno == ERANGE)
return 1;
@@
-152,7
+157,7
@@
void strip_blank_front(char **p)
void strip_blank_end(char *p)
{
void strip_blank_end(char *p)
{
- char *s;
+ char *s
tart = p, *s
;
s = strchr(p, ';');
if (s)
s = strchr(p, ';');
if (s)
@@
-164,7
+169,7
@@
void strip_blank_end(char *p)
p = s;
s = p + strlen(p);
p = s;
s = p + strlen(p);
- while ((isspace(*s) || iscntrl(*s)) && (s >
p
))
+ while ((isspace(*s) || iscntrl(*s)) && (s >
start
))
s--;
*(s + 1) = '\0';
s--;
*(s + 1) = '\0';
@@
-236,7
+241,7
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
o->type, ptr);
dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
o->type, ptr);
- if (!ptr && o->type != FIO_OPT_STR_SET) {
+ if (!ptr && o->type != FIO_OPT_STR_SET
&& o->type != FIO_OPT_STR
) {
fprintf(stderr, "Option %s requires an argument\n", o->name);
return 1;
}
fprintf(stderr, "Option %s requires an argument\n", o->name);
return 1;
}
@@
-272,6
+277,7
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
}
case FIO_OPT_STR_VAL_TIME:
is_time = 1;
}
case FIO_OPT_STR_VAL_TIME:
is_time = 1;
+ case FIO_OPT_INT:
case FIO_OPT_STR_VAL:
case FIO_OPT_STR_VAL_INT: {
fio_opt_str_val_fn *fn = o->cb;
case FIO_OPT_STR_VAL:
case FIO_OPT_STR_VAL_INT: {
fio_opt_str_val_fn *fn = o->cb;
@@
-298,7
+304,8
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
if (fn)
ret = fn(data, &ull);
else {
if (fn)
ret = fn(data, &ull);
else {
- if (o->type == FIO_OPT_STR_VAL_INT) {
+ if (o->type == FIO_OPT_STR_VAL_INT ||
+ o->type == FIO_OPT_INT) {
if (first)
val_store(ilp, ull, o->off1, data);
if (!more && o->off2)
if (first)
val_store(ilp, ull, o->off1, data);
if (!more && o->off2)
@@
-368,7
+375,6
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
break;
}
break;
}
- case FIO_OPT_INT:
case FIO_OPT_BOOL: {
fio_opt_int_fn *fn = o->cb;
case FIO_OPT_BOOL: {
fio_opt_int_fn *fn = o->cb;
@@
-424,12
+430,16
@@
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
return ret;
}
return ret;
}
-static int handle_option(struct fio_option *o, const char *ptr, void *data)
+static int handle_option(struct fio_option *o, const char *
__
ptr, void *data)
{
{
- c
onst char
*ptr2 = NULL;
+ c
har *ptr,
*ptr2 = NULL;
int r1, r2;
int r1, r2;
- dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, ptr);
+ dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, __ptr);
+
+ ptr = NULL;
+ if (__ptr)
+ ptr = strdup(__ptr);
/*
* See if we have a second set of parameters, hidden after a comma.
/*
* See if we have a second set of parameters, hidden after a comma.
@@
-440,6
+450,8
@@
static int handle_option(struct fio_option *o, const char *ptr, void *data)
(o->type != FIO_OPT_STR_STORE) &&
(o->type != FIO_OPT_STR)) {
ptr2 = strchr(ptr, ',');
(o->type != FIO_OPT_STR_STORE) &&
(o->type != FIO_OPT_STR)) {
ptr2 = strchr(ptr, ',');
+ if (ptr2 && *(ptr2 + 1) == '\0')
+ *ptr2 = '\0';
if (!ptr2)
ptr2 = strchr(ptr, ':');
if (!ptr2)
if (!ptr2)
ptr2 = strchr(ptr, ':');
if (!ptr2)
@@
-453,12
+465,17
@@
static int handle_option(struct fio_option *o, const char *ptr, void *data)
*/
r1 = __handle_option(o, ptr, data, 1, !!ptr2);
*/
r1 = __handle_option(o, ptr, data, 1, !!ptr2);
- if (!ptr2)
+ if (!ptr2) {
+ if (ptr)
+ free(ptr);
return r1;
return r1;
+ }
ptr2++;
r2 = __handle_option(o, ptr2, data, 0, 0);
ptr2++;
r2 = __handle_option(o, ptr2, data, 0, 0);
+ if (ptr)
+ free(ptr);
return r1 && r2;
}
return r1 && r2;
}
@@
-474,6
+491,7
@@
static struct fio_option *get_option(const char *opt,
*ret = '\0';
ret = (char *) opt;
(*post)++;
*ret = '\0';
ret = (char *) opt;
(*post)++;
+ strip_blank_end(ret);
o = find_option(options, ret);
} else {
o = find_option(options, opt);
o = find_option(options, ret);
} else {
o = find_option(options, opt);
@@
-520,7
+538,7
@@
int parse_cmd_option(const char *opt, const char *val,
o = find_option(options, opt);
if (!o) {
o = find_option(options, opt);
if (!o) {
- fprintf(stderr, "Bad option
%s
\n", opt);
+ fprintf(stderr, "Bad option
<%s>
\n", opt);
return 1;
}
return 1;
}
@@
-589,7
+607,7
@@
int parse_option(const char *opt, struct fio_option *options, void *data)
o = get_option(tmp, options, &post);
if (!o) {
o = get_option(tmp, options, &post);
if (!o) {
- fprintf(stderr, "Bad option
%s
\n", tmp);
+ fprintf(stderr, "Bad option
<%s>
\n", tmp);
free(tmp);
return 1;
}
free(tmp);
return 1;
}