mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
- Fix strange for loop.
Reported by: phk - While here, check the unit before calculating the actually number. This way we can return EINVAL for invalid unit instead of ERANGE. Approved by: re (kensmith)
This commit is contained in:
parent
c2fc8cebdd
commit
c0a6ac3ff0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=172049
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user