Paul Eggert wrote: > But I'm still puzzled. I thought vasnprintf was supplied by Gnulib and > so does not have the INT_MAX limitation. If so, why limit sizes to > INT_MAX when calling vasnprintf? > > Because of the Fil-C problem you mention (that I assume is actually with > snprintf and vsnprintf), should lib/vasnprintf.c's USE_SNPRINTF be 0 if > Fil-C is in use? I'm thinking that would work around the Fil-C bug more > generally, without the need for INT_MAX #ifdefs in callers.
You're perfectly right. Nice simplification! Committed as follows: 2026-07-26 Bruno Haible <[email protected]> [v]szprintf: Improve port to Fil-C. Suggested by Paul Eggert in <https://lists.gnu.org/archive/html/bug-gnulib/2026-07/msg00181.html>. * lib/vasnprintf.c (USE_SNPRINTF): Define to 0 on Fil-C. * lib/szprintf.c (szprintf): Revert last change. * lib/vszprintf.c (vszprintf): Likewise. * lib/unistdio/u-vsprintf.h (VSPRINTF): Likewise. diff --git a/lib/szprintf.c b/lib/szprintf.c index 651aae801e..a5a3291c9e 100644 --- a/lib/szprintf.c +++ b/lib/szprintf.c @@ -22,7 +22,6 @@ #include <stdio.h> #include <errno.h> -#include <limits.h> #include <stdarg.h> #include <stdint.h> #include <stdlib.h> @@ -39,10 +38,6 @@ 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; diff --git a/lib/unistdio/u-vsprintf.h b/lib/unistdio/u-vsprintf.h index 6f93257c17..4cc7506b54 100644 --- a/lib/unistdio/u-vsprintf.h +++ b/lib/unistdio/u-vsprintf.h @@ -39,10 +39,6 @@ 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) diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 750601cfb2..10e6af5bf9 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -230,7 +230,8 @@ || (defined __APPLE__ && defined __MACH__) \ || (defined __FreeBSD__ || defined __DragonFly__) \ || defined __OpenBSD__ \ - || defined __ANDROID__ || defined _UCRT)) + || defined __ANDROID__ || defined _UCRT) \ + && !defined __FILC__) # define USE_SNPRINTF 1 # else # define USE_SNPRINTF 0 diff --git a/lib/vszprintf.c b/lib/vszprintf.c index 2a65064541..69c6fa05bb 100644 --- a/lib/vszprintf.c +++ b/lib/vszprintf.c @@ -22,7 +22,6 @@ #include <stdio.h> #include <errno.h> -#include <limits.h> #include <stdarg.h> #include <stdint.h> #include <stdlib.h> @@ -36,10 +35,6 @@ 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;
