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 e3c8639c8dd640acc938836ab72157263d793098
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 5 12:06:50 2026 +0100

    libs/libc/stream: Read a long as an int where they have the same size.
    
    printf() has two reads for %ld and %d.  Where long has the size of int, both
    read the same slot.  One read is enough, and the code is smaller.  There is 
no
    change in the output.
    
    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/stream/lib_libvsprintf.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libs/libc/stream/lib_libvsprintf.c 
b/libs/libc/stream/lib_libvsprintf.c
index 76a0219c5c7..671f03f7e87 100644
--- a/libs/libc/stream/lib_libvsprintf.c
+++ b/libs/libc/stream/lib_libvsprintf.c
@@ -146,6 +146,10 @@
 
 #define FL_INT_UNAVAIL       (FL_INT_PREC_UNAVAIL | FL_INT_SHORT_UNAVAIL)
 
+/* Where long has the size of int, read it as an int: the code is smaller */
+
+#define FL_LONG_READ       (sizeof(long) != sizeof(int) ? FL_LONG : 0)
+
 /* A value longer than long has output only with this option */
 
 #if defined(CONFIG_LIBC_PRINTF_LONG_LONG) || ULLONG_MAX == ULONG_MAX
@@ -1393,7 +1397,7 @@ str_lpad:
                 }
             }
           else
-          if ((flags & FL_LONG) != 0)
+          if ((flags & FL_LONG_READ) != 0)
             {
 #ifdef CONFIG_LIBC_NUMBERED_ARGS
               if ((flags & FL_ARGNUMBER) != 0)
@@ -1488,7 +1492,7 @@ str_lpad:
                 }
             }
           else
-          if ((flags & FL_LONG) != 0)
+          if ((flags & FL_LONG_READ) != 0)
             {
 #ifdef CONFIG_LIBC_NUMBERED_ARGS
               if ((flags & FL_ARGNUMBER) != 0)

Reply via email to