]> 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>
Fri, 11 Apr 2025 14:45:03 +0000 (16:45 +0200)
* lib/vasnprintf.c (MAX_ROOM_NEEDED): For %g, consider also the size of
the thousands separators.

ChangeLog
lib/vasnprintf.c

index 07de3b7b97dd10b7c109d3c01ed46ea6ae01a827..adad6ce81bb599851ac60a920b98e1e651d70e6f 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-11  Bruno Haible  <bruno@clisp.org>
 
        newlocale: Support cross-compilation.
index a07c1377dd7c092877e776b0c9171013651a8dd6..559b3c70432b8758a04c53641226d81d3f99cb77 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':