diff options
author | Pawel Jakub Dawidek <pjd@FreeBSD.org> | 2007-09-05 14:27:13 +0000 |
---|---|---|
committer | Pawel Jakub Dawidek <pjd@FreeBSD.org> | 2007-09-05 14:27:13 +0000 |
commit | c0a6ac3ff07edc7474d66796e2058758a815766c (patch) | |
tree | 433fdc111f0371a66bdd38ab663c47034125d48d | |
parent | c2fc8cebdd152fb1dd0b17cbe09c7ab5108cbc37 (diff) |
Notes
-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 b9ae5d230f2b..5cc260820bb2 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); |