Paul Eggert wrote:
> (USE_SNPRINTF): Define to 1 only if glibc 2+, Android, musl,
> the BSDs, macOS, or Microsoft UCRT.
On NetBSD 10.0, this patch causes several test failures:
FAIL: test-sprintf-gnu
FAIL: test-sprintf-posix
FAIL: test-szprintf-gnu
FAIL: test-szprintf-posix
[1] Segmentation fault (core dumped) "${@}" >>"${log_file}" 2>&1
FAIL: test-u16-vsprintf1
[1] Segmentation fault (core dumped) "${@}" >>"${log_file}" 2>&1
FAIL: test-u32-vsprintf1
FAIL: test-vsprintf-gnu
FAIL: test-vsprintf-posix
FAIL: test-vszprintf-gnu
FAIL: test-vszprintf-posix
The most prominent among these failures is:
FAIL: test-sprintf-posix
========================
../../gltests/test-sprintf-posix.h:91: assertion 'retval == 5' failed
FAIL test-sprintf-posix (exit status: 134)
In other words, rpl_sprintf() does not work at all any more.
Debugging this, I see that the cause is a failing snprintf() call
with size = INT_MAX + 1u.
2026-07-13 Bruno Haible <[email protected]>
vasnprintf: Fix several test failures on NetBSD (regr. 2026-07-06).
* lib/vasnprintf.c (USE_SNPRINTF): Don't enable on NetBSD.
* doc/posix-functions/snprintf.texi: Update regarding NetBSD.
* doc/posix-functions/vsnprintf.texi: Likewise.
diff --git a/doc/posix-functions/snprintf.texi
b/doc/posix-functions/snprintf.texi
index 2a75e2fd32..e05b89ce49 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -140,11 +140,11 @@
@item
This function fails if the buffer size exceeds @code{INT_MAX},
even if the resulting string length would fit in @code{int}:
-Solaris, z/OS.
+NetBSD, Solaris, z/OS.
@item
This function fails if the buffer size exceeds @code{INT_MAX + 1u},
even if the resulting string length would fit in @code{int}:
-FreeBSD, OpenBSD, NetBSD, macOS.
+FreeBSD, OpenBSD, macOS.
@item
The @code{%m} directive is not portable, use @code{%s} mapped to an
argument of @code{strerror(errno)} (or a version of @code{strerror_r})
diff --git a/doc/posix-functions/vsnprintf.texi
b/doc/posix-functions/vsnprintf.texi
index 52d7dacda1..27f3efc5d8 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -138,11 +138,11 @@
@item
This function fails if the buffer size exceeds @code{INT_MAX},
even if the resulting string length would fit in @code{int}:
-Solaris, z/OS.
+NetBSD, Solaris, z/OS.
@item
This function fails if the buffer size exceeds @code{INT_MAX + 1u},
even if the resulting string length would fit in @code{int}:
-FreeBSD, OpenBSD, NetBSD, macOS.
+FreeBSD, OpenBSD, macOS.
@item
The @code{%m} directive is not portable, use @code{%s} mapped to an
argument of @code{strerror(errno)} (or a version of @code{strerror_r})
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 1b5b5b4764..bd0c0d6c98 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -219,18 +219,17 @@
/* TCHAR_T is char. */
/* Use snprintf if it exists under the name 'snprintf' or '_snprintf'.
But don't use it if it has problems. For example,
- Solaris, QNX and z/OS snprintf fail if size == INT_MAX + 1u,
+ NetBSD, Solaris, QNX and z/OS snprintf fail if size == INT_MAX + 1u,
BeOS snprintf produces no output if size >= 0x3000000,
and Linux libc5 with size == 1 writes without bounds, like sprintf.
BSD snprintf, which fails if size == INT_MAX + 2u, is OK for us.
Use snprintf only on known-safe platforms:
- glibc 2, musl libc, macOS, FreeBSD, NetBSD, OpenBSD, Android,
- Microsoft UCRT. */
+ glibc 2, musl libc, macOS, FreeBSD, OpenBSD, Android, Microsoft UCRT. */
# if ((HAVE_SNPRINTF || HAVE_DECL__SNPRINTF) \
&& (2 <= __GLIBC__ || MUSL_LIBC \
|| (defined __APPLE__ && defined __MACH__) \
|| (defined __FreeBSD__ || defined __DragonFly__) \
- || defined __NetBSD__ || defined __OpenBSD__ \
+ || defined __OpenBSD__ \
|| defined __ANDROID__ || defined _UCRT))
# define USE_SNPRINTF 1
# else