From 9320638848febcd01f5a2e7ccdee63d649d823d0 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Thu, 28 Dec 2023 21:59:02 +0800 Subject: [PATCH] libc/stdlib: Refine octal check of lib_checkbase() Signed-off-by: wangjianyu3 --- libs/libc/stdlib/lib_checkbase.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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; } } }