diff options
author | Anna Zaks <ganna@apple.com> | 2012-01-31 19:33:39 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-01-31 19:33:39 +0000 |
commit | e00575f12cf280621ef0ed4d69e909bdfc9fef62 (patch) | |
tree | 2b3e9d85103550c967dd4c577ad6cccc4730a599 /lib/StaticAnalyzer/Core/CheckerContext.cpp | |
parent | 393b9793da0b62e26e3974c88a0bca18f2d7fd5e (diff) |
[analyzer] Add checks for common anti-patterns in strncat.
(Since this is syntax only, might be a good candidate for turning into a
compiler warning.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/CheckerContext.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/CheckerContext.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/StaticAnalyzer/Core/CheckerContext.cpp b/lib/StaticAnalyzer/Core/CheckerContext.cpp index c25ba36a51..ccf415f0c7 100644 --- a/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -37,19 +37,27 @@ StringRef CheckerContext::getCalleeName(const FunctionDecl *FunDecl) const { bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, - StringRef Name){ + StringRef Name) { + return isCLibraryFunction(FD, Name, getASTContext()); +} + +bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, + StringRef Name, ASTContext &Context) { // To avoid false positives (Ex: finding user defined functions with // similar names), only perform fuzzy name matching when it's a builtin. // Using a string compare is slow, we might want to switch on BuiltinID here. unsigned BId = FD->getBuiltinID(); if (BId != 0) { - ASTContext &Context = getASTContext(); StringRef BName = Context.BuiltinInfo.GetName(BId); - if (StringRef(BName).find(Name) != StringRef::npos) + if (BName.find(Name) != StringRef::npos) return true; } - if (FD->isExternC() && FD->getIdentifier()->getName().equals(Name)) + StringRef FName = FD->getIdentifier()->getName(); + if (FName.startswith("__inline")) + return (FName.find(Name) != StringRef::npos); + + if (FD->isExternC() && FName.equals(Name)) return true; return false; |