mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:43:28 +08:00
libc/stdlib: Check if there is next char before assuming octal
When *pptr/ptr is "0" and base is 0, lib_checkbase() returns the error base 8(should be 10).
e.g. `strtoul("0", &endptr, 0);`
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
@@ -69,18 +69,21 @@ int lib_checkbase(int base, FAR const char **pptr)
|
|||||||
|
|
||||||
if (*ptr == '0')
|
if (*ptr == '0')
|
||||||
{
|
{
|
||||||
/* Assume octal */
|
if (ptr[1] != '\0')
|
||||||
|
|
||||||
base = 8;
|
|
||||||
ptr++;
|
|
||||||
|
|
||||||
/* Check for hexadecimal */
|
|
||||||
|
|
||||||
if ((*ptr == 'X' || *ptr == 'x') &&
|
|
||||||
lib_isbasedigit(ptr[1], 16, NULL))
|
|
||||||
{
|
{
|
||||||
base = 16;
|
/* Assume octal */
|
||||||
|
|
||||||
|
base = 8;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
|
/* Check for hexadecimal */
|
||||||
|
|
||||||
|
if ((*ptr == 'X' || *ptr == 'x') &&
|
||||||
|
lib_isbasedigit(ptr[1], 16, NULL))
|
||||||
|
{
|
||||||
|
base = 16;
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user