Skip to content

Commit ef75da0

Browse files
committed
vasnprintf: Fix compilation error on MSVC (regression 2026-07-06).
* lib/vasnprintf.c (USE_SNPRINTF): Fix condition. (VASNPRINTF): Avoid declaring multiple variables in one declaration.
1 parent 1eb434d commit ef75da0

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2026-07-13 Bruno Haible <bruno@clisp.org>
2+
3+
vasnprintf: Fix compilation error on MSVC (regression 2026-07-06).
4+
* lib/vasnprintf.c (USE_SNPRINTF): Fix condition.
5+
(VASNPRINTF): Avoid declaring multiple variables in one declaration.
6+
17
2026-07-12 Bruno Haible <bruno@clisp.org>
28

39
Remove unnecessary include after 2026-06-26 change.

lib/vasnprintf.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,19 @@
219219
/* TCHAR_T is char. */
220220
/* Use snprintf if it exists under the name 'snprintf' or '_snprintf'.
221221
But don't use it if it has problems. For example,
222-
Solaris, QNX and z/OS sprintf fail if size == INT_MAX + 1u,
223-
BeOS produces no output if 0x3000000 <= size,
224-
and Linux libc5 with size = 1 writes without bounds, like sprintf.
222+
Solaris, QNX and z/OS snprintf fail if size == INT_MAX + 1u,
223+
BeOS snprintf produces no output if size >= 0x3000000,
224+
and Linux libc5 with size == 1 writes without bounds, like sprintf.
225225
BSD snprintf, which fails if size == INT_MAX + 2u, is OK for us.
226226
Use snprintf only on known-safe platforms:
227-
glibc 2, Android, musl, the BSDs, macOS, Microsoft UCRT. */
227+
glibc 2, musl libc, macOS, FreeBSD, NetBSD, OpenBSD, Android,
228+
Microsoft UCRT. */
228229
# if ((HAVE_SNPRINTF || HAVE_DECL__SNPRINTF) \
229-
&& (2 <= __GLIBC__ || __ANDROID__ || MUSL_LIBC \
230-
|| __FreeBSD__ || __DragonFly__ || __NetBSD__ || __OpenBSD__ \
231-
|| (__APPLE__ && __MACH__) || _UCRT))
230+
&& (2 <= __GLIBC__ || MUSL_LIBC \
231+
|| (defined __APPLE__ && defined __MACH__) \
232+
|| (defined __FreeBSD__ || defined __DragonFly__) \
233+
|| defined __NetBSD__ || defined __OpenBSD__ \
234+
|| defined __ANDROID__ || defined _UCRT))
232235
# define USE_SNPRINTF 1
233236
# else
234237
# define USE_SNPRINTF 0
@@ -6868,17 +6871,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
68686871

68696872
/* Keep size (in bytes) in ptrdiff_t and size_t range.
68706873
Also, generate at most INT_MAX + 1 characters
6871-
counting the trailing null, as that is the
6874+
counting the trailing NUL, as that is the
68726875
maximum the API allows. */
6873-
size_t
6874-
bytes_max = MIN (PTRDIFF_MAX, SIZE_MAX),
6875-
tchars_max = bytes_max / sizeof (TCHAR_T),
6876-
API_max = MIN (tchars_max - 1, INT_MAX),
6877-
maxlen_max = (API_max + 1
6878-
- (API_max + 1) % TCHARS_PER_DCHAR),
6879-
maxlen = (MIN (allocated - length,
6880-
maxlen_max / TCHARS_PER_DCHAR)
6881-
* TCHARS_PER_DCHAR);
6876+
size_t bytes_max = MIN (PTRDIFF_MAX, SIZE_MAX);
6877+
size_t tchars_max = bytes_max / sizeof (TCHAR_T);
6878+
size_t API_max = MIN (tchars_max - 1, INT_MAX);
6879+
size_t maxlen_max =
6880+
(API_max + 1) - (API_max + 1) % TCHARS_PER_DCHAR;
6881+
size_t maxlen =
6882+
MIN (allocated - length, maxlen_max / TCHARS_PER_DCHAR)
6883+
* TCHARS_PER_DCHAR;
68826884
# define SNPRINTF_BUF(arg) \
68836885
switch (prefix_count) \
68846886
{ \

0 commit comments

Comments
 (0)