$ LC_ALL=fr_FR.UTF-8 printf "%'.50g\\n" 42351647362715016953416125033982098102569580078125,0 42 351 647 362 715 016 952 456 886 422 478 691 899 620 590 616 576
The vasnprintf code, so far, does not consider the possibility of so many thousands separators in the %g output. This patch fixes it. 2025-04-11 Bruno Haible <br...@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. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index a07c1377dd..559b3c7043 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -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':