r184214 - Correctly compute the index of the first string format argument when deciding
Eli Friedman
eli.friedman at gmail.com
Tue Jun 18 11:10:01 PDT 2013
Author: efriedma
Date: Tue Jun 18 13:10:01 2013
New Revision: 184214
URL: http://llvm.org/viewvc/llvm-project?rev=184214&view=rev
Log:
Correctly compute the index of the first string format argument when deciding
whether to emit a -Wformat-security warning. <rdar://problem/14178260>.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/format-strings.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=184214&r1=184213&r2=184214&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 18 13:10:01 2013
@@ -1951,7 +1951,7 @@ bool Sema::CheckFormatArguments(ArrayRef
// 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();
Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=184214&r1=184213&r2=184214&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Tue Jun 18 13:10:01 2013
@@ -591,3 +591,13 @@ void test_qualifiers(volatile int *vip,
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"
More information about the cfe-commits
mailing list