]> granicus.if.org Git - clang/commitdiff
Enhance checking for null format string literal to take into account __null. Fixes...
authorTed Kremenek <kremenek@apple.com>
Fri, 10 Feb 2012 19:13:51 +0000 (19:13 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 10 Feb 2012 19:13:51 +0000 (19:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150260 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaCXX/format-strings.cpp

index a44633d5d7ce1634bd00f3eeab5cb10a43e3daab..be326880d587e319ff86bf5500e9eff523c4e494 100644 (file)
@@ -1381,6 +1381,7 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args,
                                  inFunctionCall);
   }
 
+  case Stmt::GNUNullExprClass:
   case Stmt::IntegerLiteralClass:
     // Technically -Wformat-nonliteral does not warn about this case.
     // The behavior of printf and friends in this case is implementation
index 8b0b00d04e5bbd81833f193c09c13d0b3d3c64f4..456167dfc96f44f9d942dd06d5c0fae031b6ae2d 100644 (file)
@@ -39,3 +39,14 @@ void h(int *i) {
   printf(foo.gettext("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
   printf(Foo::gettext_static("%d"), i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
 }
+
+// Test handling __null for format string literal checking.
+extern "C" {
+  int test_null_format(const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+}
+
+void rdar8269537(const char *f)
+{
+  test_null_format(__null); // no-warning
+  test_null_format(f); // expected-warning {{not a string literal}}
+}