This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4b8b0406f80a9dd867a9b6472fee95909d8cf639
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 5 12:06:49 2026 +0100

    libs/libc/stream: Add an option for %o in printf().
    
    With LIBC_PRINTF_OCTAL off, %o reads its argument and prints "?".
    
    The option is on in all profiles.
    
    Part of https://github.com/apache/nuttx/issues/21467
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 libs/libc/stdio/Kconfig            |  6 ++++++
 libs/libc/stream/lib_libvsprintf.c | 14 +++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libs/libc/stdio/Kconfig b/libs/libc/stdio/Kconfig
index 592d30e11f7..53141430d3f 100644
--- a/libs/libc/stdio/Kconfig
+++ b/libs/libc/stdio/Kconfig
@@ -102,6 +102,12 @@ config LIBC_PRINTF_ALT_FORM
                for %#.0f.  Without it, printf() ignores the flag, so %#x of 255
                prints "ff".  %p keeps its 0x.
 
+config LIBC_PRINTF_OCTAL
+       bool "Enable %o in printf"
+       default y
+       ---help---
+               Without it, printf() reads the argument of %o and prints "?".
+
 config LIBC_FLOATINGPOINT
        bool "Enable floating point in printf"
        default LIBC_PRINTF_FULL || (!DEFAULT_SMALL && ARCH_FPU && 
!LIBC_PRINTF_MINIMAL)
diff --git a/libs/libc/stream/lib_libvsprintf.c 
b/libs/libc/stream/lib_libvsprintf.c
index 4b1882255cf..aabe98e0beb 100644
--- a/libs/libc/stream/lib_libvsprintf.c
+++ b/libs/libc/stream/lib_libvsprintf.c
@@ -109,9 +109,16 @@
 #  define FL_POINTER       (FL_ALT | FL_ALTHEX)
 #endif
 
+#ifdef CONFIG_LIBC_PRINTF_OCTAL
+#  define HAVE_OCTAL_OUTPUT 1
+#else
+#  define HAVE_OCTAL_OUTPUT 0
+#endif
+
 /* Only %x, %X and %p have FL_ALT: then FL_ALTHEX needs no test */
 
-#define FL_ALT_IS_HEX(f)   (FL_ALT_FORM == 0 || ((f) & FL_ALTHEX) != 0)
+#define FL_ALT_IS_HEX(f)   (FL_ALT_FORM == 0 || !HAVE_OCTAL_OUTPUT || \
+                            ((f) & FL_ALTHEX) != 0)
 
 /* A value longer than long has output only with this option */
 
@@ -1504,6 +1511,11 @@ str_lpad:
                 break;
 
               case 'o':
+                if (!HAVE_OCTAL_OUTPUT)
+                  {
+                    goto put_unavailable;
+                  }
+
                 base = 8;
                 break;
 

Reply via email to