I wrote:
> diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
> index bd0c0d6c98..63e59562b4 100644
> --- a/lib/vasnprintf.c
> +++ b/lib/vasnprintf.c
> @@ -576,6 +576,13 @@ thousands_separator_wchar (wchar_t stackbuf[10])
> separator. */
> #define THOUSEP_WCHAR_MAXLEN 1
>
> +/* Maximum number of units needed for a thousands separator. */
> +#if WIDE_CHAR_VERSION
> +# define THOUSEP_MAXLEN THOUSEP_WCHAR_MAXLEN
> +#else
> +# define THOUSEP_MAXLEN THOUSEP_CHAR_MAXLEN
> +#endif
> +
Oops, this is still not right: I see a test failure of
test-vasnwprintf-posix2.c:131 on NetBSD 10.0.
Here, count = 11 + 3 * 2 = 17
(strlen ("-2147483647") = 11, need 3 thousands separators, each has 2 bytes),
and tmp_length = 17, which is too small.
2026-07-13 Bruno Haible <[email protected]>
vasnwprintf: Fix test failure on NetBSD.
* lib/vasnprintf.c (THOUSEP_MAXLEN): Correct value.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 63e59562b4..dd54b29427 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -576,13 +576,6 @@ thousands_separator_wchar (wchar_t stackbuf[10])
separator. */
#define THOUSEP_WCHAR_MAXLEN 1
-/* Maximum number of units needed for a thousands separator. */
-#if WIDE_CHAR_VERSION
-# define THOUSEP_MAXLEN THOUSEP_WCHAR_MAXLEN
-#else
-# define THOUSEP_MAXLEN THOUSEP_CHAR_MAXLEN
-#endif
-
#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) ||
(NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION ||
NEED_PRINTF_FLAG_GROUPING || NEED_PRINTF_FLAG_GROUPING_INT)
# ifndef grouping_rule_defined
# define grouping_rule_defined 1
@@ -1887,6 +1880,15 @@ is_borderline (const char *digits, size_t precision)
#endif
+/* Maximum number of units needed for a thousands separator,
+ in the code that creates a temporary unit sequence of length
+ MAX_ROOM_NEEDED (...). */
+#if USE_SNPRINTF && (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)
+# define THOUSEP_MAXLEN THOUSEP_WCHAR_MAXLEN
+#else
+# define THOUSEP_MAXLEN THOUSEP_CHAR_MAXLEN
+#endif
+
#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) ||
!HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
/* Use a different function name, to make it possible that the 'wchar_t'