From: Bruno Haible Date: Sat, 25 Jul 2026 23:15:14 +0000 (+0200) Subject: szprintf: Port to Fil-C. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fd0a1fa4c76b3fe3172f69a6f99babea3ce8dbc;p=thirdparty%2Fgnulib.git 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). --- diff --git a/ChangeLog b/ChangeLog index 1f7105dcc0..6a9b47c6a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2026-07-25 Bruno Haible + [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. diff --git a/lib/szprintf.c b/lib/szprintf.c index a5a3291c9e..651aae801e 100644 --- a/lib/szprintf.c +++ b/lib/szprintf.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/lib/unistdio/u-vsprintf.h b/lib/unistdio/u-vsprintf.h index 4cc7506b54..6f93257c17 100644 --- a/lib/unistdio/u-vsprintf.h +++ b/lib/unistdio/u-vsprintf.h @@ -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) diff --git a/lib/vszprintf.c b/lib/vszprintf.c index 69c6fa05bb..2a65064541 100644 --- a/lib/vszprintf.c +++ b/lib/vszprintf.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -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;