From 55ed9636e82b8dee419b5a76c07098bff4d980b6 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 27 Mar 2011 20:55:09 +0200 Subject: [PATCH 1/1] Fix parser bug dealing with range options and postfix Signed-off-by: Jens Axboe --- parse.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/parse.c b/parse.c index e9eb7385..585fb7e0 100644 --- a/parse.c +++ b/parse.c @@ -168,19 +168,20 @@ static unsigned long long __get_mult_bytes(const char *p, void *data) static unsigned long long get_mult_bytes(const char *str, int len, void *data) { - const char *p; + const char *p = str; if (len < 2) return __get_mult_bytes(str, data); - /* - * if the last char is 'b' or 'B', the user likely used - * "1gb" instead of just "1g". If the second to last is also - * a letter, adjust. - */ - p = str + len - 1; - while (isalpha(*(p - 1))) - p--; + /* + * Go forward until we hit a non-digit + */ + while ((p - str) <= len) { + if (!isdigit(*p)) + break; + p++; + } + if (!isalpha(*p)) p = NULL; -- 2.25.1