]> 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 23:09:20 +0000 (01:09 +0200)
* lib/vasnprintf.c (MAX_ROOM_NEEDED): For %g, consider also the size of
the thousands separators.

ChangeLog
lib/vasnprintf.c

index 6e4e2bbe21590a41d8a0d6bc287cb1314a928230..4a9415a1ff518c0218082d762f0febb4c109b510 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 a0eab63f472d07495a56cfb5fdb14a6c808565e6..b195aa584c5ac9889e7babcdf8d4545a4d5f28ab 100644 (file)
@@ -2088,6 +2088,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 =
@@ -2108,10 +2114,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':