summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-29 04:59:47 +0000
committerChris Lattner <sabre@nondot.org>2009-04-29 04:59:47 +0000
commitcc5d1c2e4e8b874004715835982edf70de2ceff4 (patch)
tree7f89774b6127a1d04f51307ee25b83e4bb052325 /clang/lib/Sema/SemaChecking.cpp
parente009a881eac3db71dd2664f547d5c64cff772cc5 (diff)
downloadbcm5719-llvm-cc5d1c2e4e8b874004715835982edf70de2ceff4.tar.gz
bcm5719-llvm-cc5d1c2e4e8b874004715835982edf70de2ceff4.zip
implement -Wformat-security properly, which is enabled by default.
This enables one specific class of non-literal format warnings. llvm-svn: 70368
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d355ba4e992..3e46300b604 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/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,
OpenPOWER on IntegriCloud