parser: relax restriction on postfix ranges
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Mar 2012 09:53:29 +0000 (10:53 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Mar 2012 09:53:29 +0000 (10:53 +0100)
Currently we misparse this option:

bs=1k,4k

as read_bs=1, and write_bs=4096, since we compare the postfix
strictly against "k,4k". Use range compares instead.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
parse.c

diff --git a/parse.c b/parse.c
index f1d5f8f8a72922a85d511528b58f9796c77c337b..cdd9ac7e3cf0cb9e81a25d2fd43aba205c90ce88 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -153,32 +153,32 @@ static unsigned long long __get_mult_bytes(const char *p, void *data,
        for (i = 0; i < strlen(c); i++)
                c[i] = tolower(c[i]);
 
        for (i = 0; i < strlen(c); i++)
                c[i] = tolower(c[i]);
 
-       if (!strcmp("pib", c)) {
+       if (!strncmp("pib", c, 3)) {
                pow = 5;
                mult = 1000;
                pow = 5;
                mult = 1000;
-       } else if (!strcmp("tib", c)) {
+       } else if (!strncmp("tib", c, 3)) {
                pow = 4;
                mult = 1000;
                pow = 4;
                mult = 1000;
-       } else if (!strcmp("gib", c)) {
+       } else if (!strncmp("gib", c, 3)) {
                pow = 3;
                mult = 1000;
                pow = 3;
                mult = 1000;
-       } else if (!strcmp("mib", c)) {
+       } else if (!strncmp("mib", c, 3)) {
                pow = 2;
                mult = 1000;
                pow = 2;
                mult = 1000;
-       } else if (!strcmp("kib", c)) {
+       } else if (!strncmp("kib", c, 3)) {
                pow = 1;
                mult = 1000;
                pow = 1;
                mult = 1000;
-       } else if (!strcmp("p", c) || !strcmp("pb", c))
+       } else if (!strncmp("p", c, 1) || !strncmp("pb", c, 2))
                pow = 5;
                pow = 5;
-       else if (!strcmp("t", c) || !strcmp("tb", c))
+       else if (!strncmp("t", c, 1) || !strncmp("tb", c, 2))
                pow = 4;
                pow = 4;
-       else if (!strcmp("g", c) || !strcmp("gb", c))
+       else if (!strncmp("g", c, 1) || !strncmp("gb", c, 2))
                pow = 3;
                pow = 3;
-       else if (!strcmp("m", c) || !strcmp("mb", c))
+       else if (!strncmp("m", c, 1) || !strncmp("mb", c, 2))
                pow = 2;
                pow = 2;
-       else if (!strcmp("k", c) || !strcmp("kb", c))
+       else if (!strncmp("k", c, 1) || !strncmp("kb", c, 2))
                pow = 1;
                pow = 1;
-       else if (!strcmp("%", c)) {
+       else if (!strncmp("%", c, 1)) {
                *percent = 1;
                free(c);
                return ret;
                *percent = 1;
                free(c);
                return ret;