From 1520dae606e95a6343e293fb794d3cef31419b01 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 9 Sep 2010 03:51:42 +0000 Subject: [PATCH] It appears that technically a null format string is not warned under -Wformat-nonliteral, as the function processing the format string can decided whether or not to accept a null format string (e.g., asl_log). Fixes . llvm-svn: 113469 --- clang/lib/Sema/SemaChecking.cpp | 7 +++++++ clang/test/Sema/format-strings.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 6092348004e6..1a7bd1d07fc6 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -955,6 +955,13 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, format_idx, firstDataArg, isPrintf); } + case Stmt::IntegerLiteralClass: + // Technically -Wformat-nonliteral does not warn about this case. + // The behavior of printf and friends in this case is implementation + // dependent. Ideally if the format string cannot be null then + // it should have a 'nonnull' attribute in the function prototype. + return true; + case Stmt::ImplicitCastExprClass: { E = cast(E)->getSubExpr(); goto tryAgain; diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 2325454c0b75..9e8007b9b02d 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -301,3 +301,10 @@ void pr7981(wint_t c, wchar_t c2) { printf("%lc", c2); // no-warning } +// -Wformat-security says NULL is not a string literal +void r8269537() { + // This is likely to crash in most cases, but -Wformat-nonliteral technically + // doesn't warn in this case. + printf(0); // no-warning +} +