From 56c6d2673199f6074ae63321b7a257ce4535e06c Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 20 Aug 2018 23:03:55 +0000 Subject: [PATCH] PR tree-optimization/87034 - missing -Wformat-overflow on a sprintf %s with a wide string gcc/testsuite/ChangeLog: * gcc.dg/builtin-sprintf-warn-20.c: New test. From-SVN: r263676 --- gcc/testsuite/ChangeLog | 5 +++++ .../gcc.dg/tree-ssa/builtin-sprintf-warn-20.c | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-20.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 969e03658f9..3708a5c4438 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-20 Martin Sebor + + PR tree-optimization/87034 + * gcc.dg/builtin-sprintf-warn-20.c: New test. + 2018-08-20 David Malcolm 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 index 00000000000..5966eab03d0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-20.c @@ -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 *-*-*} } */ +} -- 2.30.2