From: Eli Friedman Date: Tue, 18 Jun 2013 18:10:01 +0000 (+0000) Subject: Correctly compute the index of the first string format argument when deciding X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2243e78a6580ead4d17b76c924cd4b630b50d6ae;p=clang Correctly compute the index of the first string format argument when deciding whether to emit a -Wformat-security warning. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184214 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index da24667804..c6d2362908 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1951,7 +1951,7 @@ bool Sema::CheckFormatArguments(ArrayRef 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/test/Sema/format-strings.c b/test/Sema/format-strings.c index ba12721489..6da027e02c 100644 --- a/test/Sema/format-strings.c +++ b/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" +// +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"