diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-06-18 18:10:01 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-06-18 18:10:01 +0000 |
commit | 0e5d677fc372e352880890e9d75b31c9798a0d2f (patch) | |
tree | 54fb8bf316ab0fe56a5d0b0697d3a85373ed5bc6 | |
parent | 141b2acb9de56f7bd5d171ce773653000eacf583 (diff) | |
download | bcm5719-llvm-0e5d677fc372e352880890e9d75b31c9798a0d2f.tar.gz bcm5719-llvm-0e5d677fc372e352880890e9d75b31c9798a0d2f.zip |
Correctly compute the index of the first string format argument when deciding
whether to emit a -Wformat-security warning. <rdar://problem/14178260>.
llvm-svn: 184214
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 2 | ||||
-rw-r--r-- | clang/test/Sema/format-strings.c | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index da24667804b..c6d2362908f 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1951,7 +1951,7 @@ bool Sema::CheckFormatArguments(ArrayRef<const Expr *> Args, // If there are no arguments specified, warn with -Wformat-security, otherwise // warn only with -Wformat-nonliteral. - if (Args.size() == format_idx+1) + if (Args.size() == firstDataArg) Diag(Args[format_idx]->getLocStart(), diag::warn_format_nonliteral_noargs) << OrigFormatExpr->getSourceRange(); diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index ba127214897..6da027e02c6 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -591,3 +591,13 @@ void test_qualifiers(volatile int *vip, const int *cip, printf("%n", (ip_t)0); // No warning. printf("%n", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}} } + +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#pragma GCC diagnostic warning "-Wformat-security" +// <rdar://problem/14178260> +extern void test_format_security_extra_args(const char*, int, ...) + __attribute__((__format__(__printf__, 1, 3))); +void test_format_security_pos(char* string) { + test_format_security_extra_args(string, 5); // expected-warning {{format string is not a string literal (potentially insecure)}} +} +#pragma GCC diagnostic warning "-Wformat-nonliteral" |