mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:22:18 +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:
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user