PR tree-optimization/87034 - missing -Wformat-overflow on a sprintf %s with a wide...
authorMartin Sebor <msebor@redhat.com>
Mon, 20 Aug 2018 23:03:55 +0000 (23:03 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 20 Aug 2018 23:03:55 +0000 (17:03 -0600)
gcc/testsuite/ChangeLog:
* gcc.dg/builtin-sprintf-warn-20.c: New test.

From-SVN: r263676

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-20.c [new file with mode: 0644]

index 969e03658f9bbcd7ba8615c0070f33702b2b66c3..3708a5c4438f5097ce41e68df53452fd2f0e0808 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-20  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/87034
+       * gcc.dg/builtin-sprintf-warn-20.c: New test.
+
 2018-08-20  David Malcolm  <dmalcolm@redhat.com>
 
        PR other/84889
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-20.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-20.c
new file mode 100644 (file)
index 0000000..5966eab
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR tree-optimization/87034 - missing -Wformat-overflow on a sprintf
+   %s with a wide string
+   { dg-do compile }
+   { dg-options "-O2 -Wall -Wformat-overflow -ftrack-macro-expansion=0" } */
+
+typedef __WCHAR_TYPE__ wchar_t;
+
+extern int sprintf (char*, const char*, ...);
+
+struct S
+{
+  char a[1];
+  void (*pf)(void);
+};
+
+void test (struct S *p)
+{
+  const char *q = sizeof (wchar_t) == 2
+    ? (char*)L"\x4142\x4344" : (char*)L"\x41424344\x45464748";
+
+  sprintf (p->a, "%s", q);   /* { dg-warning "\\\[-Wformat-overflow" "pr87034" { xfail *-*-*} } */
+}