]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/87034 - missing -Wformat-overflow on a sprintf %s with a wide...
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 20 Aug 2018 23:03:55 +0000 (23:03 +0000)
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 20 Aug 2018 23:03:55 +0000 (23:03 +0000)
gcc/testsuite/ChangeLog:
* gcc.dg/builtin-sprintf-warn-20.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263676 138bc75d-0d04-0410-961f-82ee72b054a4

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 *-*-*} } */
+}