aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-08-25 00:32:42 +0000
committerAnna Zaks <ganna@apple.com>2011-08-25 00:32:42 +0000
commit6b7aad989f45a4684981b604ad603f53a5ef6f65 (patch)
tree279b3a033c5ee44dcafbf3485142c30dc13164d0 /lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
parentb6cfc09d40ed73163373bec3fe240270326ad478 (diff)
[analyzer] MacOSKeychainAPIChecker: Add the custom BugReport visitor(which highlights the allocation site) to all the relevant reports within the checker.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138531 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
index f89266f111..936e2477c0 100644
--- a/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
@@ -97,10 +97,9 @@ private:
BT.reset(new BugType("Improper use of SecKeychain API", "Mac OS API"));
}
- void generateDeallocatorMismatchReport(const AllocationState &AS,
+ void generateDeallocatorMismatchReport(const AllocationPair &AP,
const Expr *ArgExpr,
- CheckerContext &C,
- SymbolRef ArgSM) const;
+ CheckerContext &C) const;
BugReport *generateAllocatedDataNotReleasedReport(const AllocationPair &AP,
ExplodedNode *N) const;
@@ -260,12 +259,11 @@ bool MacOSKeychainAPIChecker::definitelyReturnedError(SymbolRef RetSym,
// Report deallocator mismatch. Remove the region from tracking - reporting a
// missing free error after this one is redundant.
void MacOSKeychainAPIChecker::
- generateDeallocatorMismatchReport(const AllocationState &AS,
+ generateDeallocatorMismatchReport(const AllocationPair &AP,
const Expr *ArgExpr,
- CheckerContext &C,
- SymbolRef ArgSM) const {
+ CheckerContext &C) const {
const ProgramState *State = C.getState();
- State = State->remove<AllocatedData>(ArgSM);
+ State = State->remove<AllocatedData>(AP.first);
ExplodedNode *N = C.generateNode(State);
if (!N)
@@ -273,11 +271,13 @@ void MacOSKeychainAPIChecker::
initBugType();
llvm::SmallString<80> sbuf;
llvm::raw_svector_ostream os(sbuf);
- unsigned int PDeallocIdx = FunctionsToTrack[AS.AllocatorIdx].DeallocatorIdx;
+ unsigned int PDeallocIdx =
+ FunctionsToTrack[AP.second->AllocatorIdx].DeallocatorIdx;
os << "Deallocator doesn't match the allocator: '"
<< FunctionsToTrack[PDeallocIdx].Name << "' should be used.";
BugReport *Report = new BugReport(*BT, os.str(), N);
+ Report->addVisitor(new SecKeychainBugVisitor(AP.first));
Report->addRange(ArgExpr->getSourceRange());
C.EmitReport(Report);
}
@@ -319,6 +319,7 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
<< FunctionsToTrack[DIdx].Name
<< "'.";
BugReport *Report = new BugReport(*BT, os.str(), N);
+ Report->addVisitor(new SecKeychainBugVisitor(V));
Report->addRange(ArgExpr->getSourceRange());
C.EmitReport(Report);
}
@@ -383,7 +384,8 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
// NULL ~ default deallocator, so warn.
if (DeallocatorExpr->isNullPointerConstant(C.getASTContext(),
Expr::NPC_ValueDependentIsNotNull)) {
- generateDeallocatorMismatchReport(*AS, ArgExpr, C, ArgSM);
+ const AllocationPair AP = std::make_pair(ArgSM, AS);
+ generateDeallocatorMismatchReport(AP, ArgExpr, C);
return;
}
// One of the default allocators, so warn.
@@ -392,7 +394,8 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
if (DeallocatorName == "kCFAllocatorDefault" ||
DeallocatorName == "kCFAllocatorSystemDefault" ||
DeallocatorName == "kCFAllocatorMalloc") {
- generateDeallocatorMismatchReport(*AS, ArgExpr, C, ArgSM);
+ const AllocationPair AP = std::make_pair(ArgSM, AS);
+ generateDeallocatorMismatchReport(AP, ArgExpr, C);
return;
}
// If kCFAllocatorNull, which does not deallocate, we still have to
@@ -415,7 +418,8 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
// Check if the proper deallocator is used.
unsigned int PDeallocIdx = FunctionsToTrack[AS->AllocatorIdx].DeallocatorIdx;
if (PDeallocIdx != idx || (FunctionsToTrack[idx].Kind == ErrorAPI)) {
- generateDeallocatorMismatchReport(*AS, ArgExpr, C, ArgSM);
+ const AllocationPair AP = std::make_pair(ArgSM, AS);
+ generateDeallocatorMismatchReport(AP, ArgExpr, C);
return;
}
@@ -427,6 +431,7 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
initBugType();
BugReport *Report = new BugReport(*BT,
"Call to free data when error was returned during allocation.", N);
+ Report->addVisitor(new SecKeychainBugVisitor(ArgSM));
Report->addRange(ArgExpr->getSourceRange());
C.EmitReport(Report);
return;