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