diff --git a/libs/libc/stdlib/lib_checkbase.c b/libs/libc/stdlib/lib_checkbase.c index c70c436cf2..ad8f112680 100644 --- a/libs/libc/stdlib/lib_checkbase.c +++ b/libs/libc/stdlib/lib_checkbase.c @@ -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; } } }