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:
wangjianyu3
2023-12-26 17:06:38 +08:00
committed by Xiang Xiao
parent 1bb0f19fd5
commit 9773fb9867
+3
View File
@@ -68,6 +68,8 @@ int lib_checkbase(int base, FAR const char **pptr)
*/ */
if (*ptr == '0') if (*ptr == '0')
{
if (ptr[1] != '\0')
{ {
/* Assume octal */ /* Assume octal */
@@ -84,6 +86,7 @@ int lib_checkbase(int base, FAR const char **pptr)
} }
} }
} }
}
/* If it a hexadecimal representation, /* If it a hexadecimal representation,
* than discard any leading "0X" or "0x" * than discard any leading "0X" or "0x"