]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
szprintf: Port to Fil-C.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Jul 2026 23:15:14 +0000 (01:15 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Jul 2026 23:49:48 +0000 (01:49 +0200)
* lib/szprintf.c (szprintf): Ensure lenbuf is at most INT_MAX.
* lib/vszprintf.c (vszprintf): Likewise.
* lib/unistdio/u-vsprintf.h (VSPRINTF): Ensure lenbuf is at most
INT_MAX / sizeof (DCHAR_T).

ChangeLog
lib/szprintf.c
lib/unistdio/u-vsprintf.h
lib/vszprintf.c

index 1f7105dcc086767c325d60e61c54896cde45bef3..6a9b47c6a92d3841bfd9095d070aeefc83a8ccc3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2026-07-25  Bruno Haible  <bruno@clisp.org>
 
+       [v]szprintf: Port to Fil-C.
+       * lib/szprintf.c (szprintf): Ensure lenbuf is at most INT_MAX.
+       * lib/vszprintf.c (vszprintf): Likewise.
+       * lib/unistdio/u-vsprintf.h (VSPRINTF): Ensure lenbuf is at most
+       INT_MAX / sizeof (DCHAR_T).
+
        fpucw: Avoid runtime error with Fil-C.
        * lib/fpucw.h: Use no-op definitions with Fil-C.
 
index a5a3291c9e174d7a07a2ef063cc229a8dc6ac6f7..651aae801e890c5d36090bd8ff6c81457a0290db 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 
 #include <errno.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -38,6 +39,10 @@ szprintf (char *str, const char *format, ...)
   size_t lenbuf = SIZE_MAX;
   if (lenbuf >= ~ (uintptr_t) str)
     lenbuf = ~ (uintptr_t) str;
+#if defined __FILC__
+  if (lenbuf > INT_MAX)
+    lenbuf = INT_MAX;
+#endif
 
   char *output = vasnprintf (str, &lenbuf, format, args);
   size_t len = lenbuf;
index 4cc7506b54d7c22be10b6ab8db7a7c95401021a2..6f93257c179773337405dd03285a69732d261485 100644 (file)
@@ -39,6 +39,10 @@ VSPRINTF (DCHAR_T *buf, const FCHAR_T *format, va_list args)
   size_t length = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
   if (length > (~ (uintptr_t) buf) / sizeof (DCHAR_T))
     length = (~ (uintptr_t) buf) / sizeof (DCHAR_T);
+#if defined __FILC__
+  if (length > INT_MAX / sizeof (DCHAR_T))
+    length = INT_MAX / sizeof (DCHAR_T);
+#endif
 
   DCHAR_T *result = VASNPRINTF (buf, &length, format, args);
   if (result == NULL)
index 69c6fa05bbaf7456b62ad31a53cd8cafeb4ab62d..2a65064541e84e2d9ea756c732f4022fc5c938a7 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 
 #include <errno.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -35,6 +36,10 @@ vszprintf (char *str, const char *format, va_list args)
   size_t lenbuf = SIZE_MAX;
   if (lenbuf >= ~ (uintptr_t) str)
     lenbuf = ~ (uintptr_t) str;
+#if defined __FILC__
+  if (lenbuf > INT_MAX)
+    lenbuf = INT_MAX;
+#endif
 
   char *output = vasnprintf (str, &lenbuf, format, args);
   size_t len = lenbuf;