mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
lib: strto: fix metric suffix parsing in strtoul[l]
While 1kB or 1kiB will be parsed correctly, 1k will return the right amount, but the metric suffix will not be escaped once the char pointer updated. Fix this situation by simplifying the move of the endp pointer. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
parent
a353e6aa8e
commit
b87b0d8d79
1 changed files with 10 additions and 12 deletions
22
lib/strto.c
22
lib/strto.c
|
@ -94,12 +94,11 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'k':
|
case 'k':
|
||||||
result *= 1024;
|
result *= 1024;
|
||||||
if ((*endp)[1] == 'i') {
|
(*endp)++;
|
||||||
if ((*endp)[2] == 'B')
|
if (**endp == 'i')
|
||||||
(*endp) += 3;
|
(*endp)++;
|
||||||
else
|
if (**endp == 'B')
|
||||||
(*endp) += 2;
|
(*endp)++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -116,12 +115,11 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'k':
|
case 'k':
|
||||||
result *= 1024;
|
result *= 1024;
|
||||||
if ((*endp)[1] == 'i') {
|
(*endp)++;
|
||||||
if ((*endp)[2] == 'B')
|
if (**endp == 'i')
|
||||||
(*endp) += 3;
|
(*endp)++;
|
||||||
else
|
if (**endp == 'B')
|
||||||
(*endp) += 2;
|
(*endp)++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue