]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Fix memory size bound for %g with grouping and precision.
authorBruno Haible <bruno@clisp.org>
Fri, 11 Apr 2025 14:45:03 +0000 (16:45 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 14 Apr 2025 22:43:10 +0000 (00:43 +0200)
* lib/vasnprintf.c (MAX_ROOM_NEEDED): For %g, consider also the size of
the thousands separators.

ChangeLog
lib/vasnprintf.c

index 457a00bed81634d0b5849e8a7b2bff95bc0bbe1e..d1ebee2b2113e117a31c76199e27d5ae5885025c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-04-11  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Fix memory size bound for %g with grouping and precision.
+       * lib/vasnprintf.c (MAX_ROOM_NEEDED): For %g, consider also the size of
+       the thousands separators.
+
 2025-04-10  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Fix handling of # flag in %b, %B directives.
index 9d6b2eab0ca8ba6c01bdbcd091c9c4ff59a023dd..7c4bedf0d6dd3e0a34b8d99d0df94a970c8a2b92 100644 (file)
@@ -2094,6 +2094,12 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       tmp_length = xsum (tmp_length, 2);
       break;
 
+    case 'e': case 'E':
+      tmp_length =
+        12; /* sign, decimal point, exponent etc. */
+      tmp_length = xsum (tmp_length, precision);
+      break;
+
     case 'f': case 'F':
       if (type == TYPE_LONGDOUBLE)
         tmp_length =
@@ -2114,10 +2120,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       tmp_length = xsum (tmp_length, precision);
       break;
 
-    case 'e': case 'E': case 'g': case 'G':
+    case 'g': case 'G':
       tmp_length =
         12; /* sign, decimal point, exponent etc. */
-      tmp_length = xsum (tmp_length, precision);
+      tmp_length = xsum (tmp_length,
+                         precision
+                         * 2 /* estimate for FLAG_GROUP */
+                        );
       break;
 
     case 'a': case 'A':