summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-10 20:18:51 +0000
committerChris Lattner <sabre@nondot.org>2007-08-10 20:18:51 +0000
commitb87b1b36eea885786dface81cf487eaffec58796 (patch)
treee72509b7fe58d851c2a8cf1290259ed00e5cd7ce /clang/Sema/SemaExpr.cpp
parentd79671fdf29b51285d620d64425290c6c24def0f (diff)
downloadbcm5719-llvm-b87b1b36eea885786dface81cf487eaffec58796.tar.gz
bcm5719-llvm-b87b1b36eea885786dface81cf487eaffec58796.zip
initial support for checking format strings, patch by Ted Kremenek:
"I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf"). Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral." llvm-svn: 41003
Diffstat (limited to 'clang/Sema/SemaExpr.cpp')
-rw-r--r--clang/Sema/SemaExpr.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index 8a3576aaf3a..6b871b4812b 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -22,6 +22,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
using namespace clang;
/// ParseStringLiteral - The specified tokens were lexed as pasted string
@@ -555,6 +556,13 @@ ParseCallExpr(ExprTy *fn, SourceLocation LParenLoc,
if (NumArgsInCall != NumArgsInProto && !proto->isVariadic())
return true;
}
+
+ // Do special checking on direct calls to functions.
+ if (ImplicitCastExpr *IcExpr = dyn_cast<ImplicitCastExpr>(Fn))
+ if (DeclRefExpr *DRExpr = dyn_cast<DeclRefExpr>(IcExpr->getSubExpr()))
+ if (FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRExpr->getDecl()))
+ CheckFunctionCall(Fn, FDecl, Args, NumArgsInCall);
+
return new CallExpr(Fn, Args, NumArgsInCall, resultType, RParenLoc);
}
OpenPOWER on IntegriCloud