[cfe-commits] r138531 - /cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp

Anna Zaks ganna at apple.com
Wed Aug 24 17:32:42 PDT 2011


Author: zaks
Date: Wed Aug 24 19:32:42 2011
New Revision: 138531

URL: http://llvm.org/viewvc/llvm-project?rev=138531&view=rev
Log:
[analyzer] MacOSKeychainAPIChecker: Add the custom BugReport visitor(which highlights the allocation site) to all the relevant reports within the checker.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp?rev=138531&r1=138530&r2=138531&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp Wed Aug 24 19:32:42 2011
@@ -97,10 +97,9 @@
       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 @@
 // 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 @@
   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 @@
               << 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 @@
       // 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 @@
         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 @@
   // 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 @@
     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;





More information about the cfe-commits mailing list