diff options
-rw-r--r-- | lib/libutil/expand_number.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/libutil/expand_number.c b/lib/libutil/expand_number.c index b9ae5d2..5cc2608 100644 --- a/lib/libutil/expand_number.c +++ b/lib/libutil/expand_number.c @@ -68,7 +68,22 @@ expand_number(char *buf, int64_t *num) } s = tolower(*endptr); - for (i = 0; i < unit[i] != '\0'; i++) { + switch (s) { + case 'b': + case 'k': + case 'm': + case 'g': + case 't': + case 'p': + case 'e': + break; + default: + /* Unrecognized unit. */ + errno = EINVAL; + return (-1); + } + + for (i = 0; unit[i] != '\0'; i++) { if (s == unit[i]) break; if ((number < 0 && (number << 10) > number) || @@ -78,11 +93,6 @@ expand_number(char *buf, int64_t *num) } number <<= 10; } - if (unit[i] == '\0') { - /* Unrecognized unit. */ - errno = EINVAL; - return (-1); - } *num = number; return (0); |