libc/stdlib: Refine octal check of lib_checkbase()

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2023-12-28 21:59:02 +08:00 committed by Xiang Xiao
parent 02f1503f9f
commit 9320638848

View File

@ -69,21 +69,21 @@ int lib_checkbase(int base, FAR const char **pptr)
if (*ptr == '0')
{
if (ptr[1] != '\0')
{
/* Assume octal */
/* Assume octal */
if (lib_isbasedigit(ptr[1], 8, NULL))
{
base = 8;
ptr++;
}
/* Check for hexadecimal */
/* Check for hexadecimal */
if ((*ptr == 'X' || *ptr == 'x') &&
lib_isbasedigit(ptr[1], 16, NULL))
{
base = 16;
ptr++;
}
else if ((ptr[1] == 'X' || ptr[1] == 'x') &&
lib_isbasedigit(ptr[2], 16, NULL))
{
base = 16;
ptr += 2;
}
}
}