55f6e7
commit 8b915921fbf4d32bf68fc3d637413cf96236b3fd
55f6e7
Author: Andreas Schwab <schwab@suse.de>
55f6e7
Date:   Mon Aug 29 15:05:40 2022 +0200
55f6e7
55f6e7
    Add test for bug 29530
55f6e7
    
55f6e7
    This tests for a bug that was introduced in commit edc1686af0 ("vfprintf:
55f6e7
    Reuse work_buffer in group_number") and fixed as a side effect of commit
55f6e7
    6caddd34bd ("Remove most vfprintf width/precision-dependent allocations
55f6e7
    (bug 14231, bug 26211).").
55f6e7
    
55f6e7
    (cherry picked from commit ca6466e8be32369a658035d69542d47603e58a99)
55f6e7
55f6e7
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
55f6e7
index d76b47bd5f932f69..ac61093660ef9063 100644
55f6e7
--- a/stdio-common/Makefile
55f6e7
+++ b/stdio-common/Makefile
55f6e7
@@ -64,7 +64,9 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
55f6e7
 	 tst-scanf-round \
55f6e7
 	 tst-renameat2 \
55f6e7
 	 tst-printf-bz25691 \
55f6e7
-	 tst-vfprintf-width-prec-alloc
55f6e7
+	 tst-vfprintf-width-prec-alloc \
55f6e7
+	 tst-grouping2 \
55f6e7
+  # tests
55f6e7
 
55f6e7
 test-srcs = tst-unbputc tst-printf tst-printfsz-islongdouble
55f6e7
 
55f6e7
@@ -91,6 +93,7 @@ $(objpfx)bug14.out: $(gen-locales)
55f6e7
 $(objpfx)scanf13.out: $(gen-locales)
55f6e7
 $(objpfx)test-vfprintf.out: $(gen-locales)
55f6e7
 $(objpfx)tst-grouping.out: $(gen-locales)
55f6e7
+$(objpfx)tst-grouping2.out: $(gen-locales)
55f6e7
 $(objpfx)tst-sprintf.out: $(gen-locales)
55f6e7
 $(objpfx)tst-sscanf.out: $(gen-locales)
55f6e7
 $(objpfx)tst-swprintf.out: $(gen-locales)
55f6e7
diff --git a/stdio-common/tst-grouping2.c b/stdio-common/tst-grouping2.c
55f6e7
new file mode 100644
55f6e7
index 0000000000000000..3024c942a60e51bf
55f6e7
--- /dev/null
55f6e7
+++ b/stdio-common/tst-grouping2.c
55f6e7
@@ -0,0 +1,39 @@
55f6e7
+/* Test printf with grouping and large width (bug 29530)
55f6e7
+   Copyright (C) 2022 Free Software Foundation, Inc.
55f6e7
+   This file is part of the GNU C Library.
55f6e7
+
55f6e7
+   The GNU C Library is free software; you can redistribute it and/or
55f6e7
+   modify it under the terms of the GNU Lesser General Public
55f6e7
+   License as published by the Free Software Foundation; either
55f6e7
+   version 2.1 of the License, or (at your option) any later version.
55f6e7
+
55f6e7
+   The GNU C Library is distributed in the hope that it will be useful,
55f6e7
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
55f6e7
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
55f6e7
+   Lesser General Public License for more details.
55f6e7
+
55f6e7
+   You should have received a copy of the GNU Lesser General Public
55f6e7
+   License along with the GNU C Library; if not, see
55f6e7
+   <https://www.gnu.org/licenses/>.  */
55f6e7
+
55f6e7
+#include <locale.h>
55f6e7
+#include <stdio.h>
55f6e7
+#include <support/check.h>
55f6e7
+#include <support/support.h>
55f6e7
+
55f6e7
+static int
55f6e7
+do_test (void)
55f6e7
+{
55f6e7
+  const int field_width = 1000;
55f6e7
+  char buf[field_width + 1];
55f6e7
+
55f6e7
+  xsetlocale (LC_NUMERIC, "de_DE.UTF-8");
55f6e7
+
55f6e7
+  /* This used to crash in group_number.  */
55f6e7
+  TEST_COMPARE (sprintf (buf, "%'*d", field_width, 1000), field_width);
55f6e7
+  TEST_COMPARE_STRING (buf + field_width - 6, " 1.000");
55f6e7
+
55f6e7
+  return 0;
55f6e7
+}
55f6e7
+
55f6e7
+#include <support/test-driver.c>