]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
vasnprintf, vasnwprintf: Revisit THOUSEP_MAXLEN.
authorBruno Haible <bruno@clisp.org>
Tue, 14 Jul 2026 10:17:24 +0000 (12:17 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 14 Jul 2026 10:17:24 +0000 (12:17 +0200)
* lib/vasnprintf.c (THOUSEP_MAXLEN): Add comment.
(VASNPRINTF): Don't use THOUSEP_MAXLEN here.

ChangeLog
lib/vasnprintf.c

index 572cef3c9889462cfd3a98d7a78d9f426aa1f67c..f78d9a2706496f0cf39861a915c9dd1d9b34c359 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-07-14  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf, vasnwprintf: Revisit THOUSEP_MAXLEN.
+       * lib/vasnprintf.c (THOUSEP_MAXLEN): Add comment.
+       (VASNPRINTF): Don't use THOUSEP_MAXLEN here.
+
 2026-07-13  Bruno Haible  <bruno@clisp.org>
 
        vasnwprintf: Fix test failure on NetBSD.
index dd54b294279c438f0a242ddb032ee03621eac749..750601cfb25df840130f7daad88b35fbeb744389 100644 (file)
@@ -1882,7 +1882,21 @@ is_borderline (const char *digits, size_t precision)
 
 /* Maximum number of units needed for a thousands separator,
    in the code that creates a temporary unit sequence of length
-   MAX_ROOM_NEEDED (...).  */
+   MAX_ROOM_NEEDED (...).
+   The tight bound is
+     (!USE_SNPRINTF && !group_ourselves
+      ? THOUSEP_CHAR_MAXLEN
+      : (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR
+         ? THOUSEP_WCHAR_MAXLEN
+         : THOUSEP_CHAR_MAXLEN))
+   But since group_ourselves is not known until runtime, we can only use this
+   upper bound:
+     (!USE_SNPRINTF
+      ? THOUSEP_CHAR_MAXLEN
+      : (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR
+         ? THOUSEP_WCHAR_MAXLEN
+         : THOUSEP_CHAR_MAXLEN))
+ */
 #if USE_SNPRINTF && (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)
 # define THOUSEP_MAXLEN THOUSEP_WCHAR_MAXLEN
 #else
@@ -5012,7 +5026,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   {
                     /* A thousands separator needs to be inserted at most every 2 digits.
                        This is the case in the ta_IN locale.  */
-                    tmp_length = xsum (tmp_length, tmp_length / 2 * THOUSEP_MAXLEN);
+# if WIDE_CHAR_VERSION
+                    tmp_length = xsum (tmp_length, tmp_length / 2 * THOUSEP_WCHAR_MAXLEN);
+# else
+                    tmp_length = xsum (tmp_length, tmp_length / 2 * THOUSEP_CHAR_MAXLEN);
+# endif
                   }
                 /* Account for sign, decimal point etc. */
                 tmp_length = xsum (tmp_length, 12);