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 c6a2e362b08767816ba498c33d16a8b879debd3b Author: Marco Casaroli <[email protected]> AuthorDate: Thu Nov 5 12:06:49 2026 +0100 libs/libc/stream: Add an option for the h and hh lengths in printf(). With LIBC_PRINTF_SHORT off, a conversion such as %hhx reads its argument and prints "?". It does not print the value without the conversion to char, because that value can be wrong for a correct call. 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 | 7 +++++++ libs/libc/stream/lib_libvsprintf.c | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libs/libc/stdio/Kconfig b/libs/libc/stdio/Kconfig index ab129096019..4d41c5484f4 100644 --- a/libs/libc/stdio/Kconfig +++ b/libs/libc/stdio/Kconfig @@ -123,6 +123,13 @@ config LIBC_PRINTF_INT_PRECISION argument and prints "?". The precision of %s and of a floating point conversion stays. +config LIBC_PRINTF_SHORT + bool "Enable the h and hh length modifiers in printf" + default y + ---help--- + Enables the conversion of the value to short or char, as in %hd and + %hhx. Without it, printf() reads the argument 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 bfb904eceb9..76a0219c5c7 100644 --- a/libs/libc/stream/lib_libvsprintf.c +++ b/libs/libc/stream/lib_libvsprintf.c @@ -136,6 +136,16 @@ # define FL_INT_PREC_UNAVAIL FL_PREC #endif +#ifdef CONFIG_LIBC_PRINTF_SHORT +# define FL_INT_SHORT FL_SHORT +# define FL_INT_SHORT_UNAVAIL 0 +#else +# define FL_INT_SHORT 0 +# define FL_INT_SHORT_UNAVAIL FL_SHORT +#endif + +#define FL_INT_UNAVAIL (FL_INT_PREC_UNAVAIL | FL_INT_SHORT_UNAVAIL) + /* A value longer than long has output only with this option */ #if defined(CONFIG_LIBC_PRINTF_LONG_LONG) || ULLONG_MAX == ULONG_MAX @@ -1409,7 +1419,7 @@ str_lpad: x = va_arg(ap, int); } - if ((flags & FL_SHORT) != 0) + if ((flags & FL_INT_SHORT) != 0) { if ((flags & FL_REPD_TYPE) == 0) { @@ -1504,7 +1514,7 @@ str_lpad: x = va_arg(ap, unsigned int); } - if ((flags & FL_SHORT) != 0) + if ((flags & FL_INT_SHORT) != 0) { if ((flags & FL_REPD_TYPE) == 0) { @@ -1635,7 +1645,7 @@ str_lpad: flags &= ~FL_NEGATIVE; } - if ((flags & FL_INT_PREC_UNAVAIL) != 0) + if ((flags & FL_INT_UNAVAIL) != 0) { goto put_unavailable; }
