diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-29 04:59:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-29 04:59:47 +0000 |
commit | 655f141f4d4c92eeebcc880211313e84c0a8b2f2 (patch) | |
tree | 40146d7fac51b0d0748d3ea166162da38e57ea75 /lib/Sema/SemaChecking.cpp | |
parent | 1cd3e1f72c3a1c256fb6a5c3d4512bca1f1b751d (diff) |
implement -Wformat-security properly, which is enabled by default.
This enables one specific class of non-literal format warnings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70368 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index d355ba4e99..3e46300b60 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -604,9 +604,16 @@ Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, if (isa<ParmVarDecl>(DR->getDecl())) return; - Diag(TheCall->getArg(format_idx)->getLocStart(), - diag::warn_printf_not_string_constant) - << OrigFormatExpr->getSourceRange(); + // If there are no arguments specified, warn with -Wformat-security, otherwise + // warn only with -Wformat-nonliteral. + if (TheCall->getNumArgs() == format_idx+1) + Diag(TheCall->getArg(format_idx)->getLocStart(), + diag::warn_printf_nonliteral_noargs) + << OrigFormatExpr->getSourceRange(); + else + Diag(TheCall->getArg(format_idx)->getLocStart(), + diag::warn_printf_nonliteral) + << OrigFormatExpr->getSourceRange(); } void Sema::CheckPrintfString(const StringLiteral *FExpr, |