]> granicus.if.org Git - clang/commitdiff
Teach ObjCContainersChecker that the array passed to CFArrayGetValueAtIndex might...
authorTed Kremenek <kremenek@apple.com>
Thu, 5 Apr 2012 05:18:05 +0000 (05:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 5 Apr 2012 05:18:05 +0000 (05:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154083 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
test/Analysis/CFContainers.mm

index 69e8fbb7ab69e17070a21128c666785deb99a9a6..207d65ad8fbed49b926e352f149a47722eb87c8c 100644 (file)
@@ -40,7 +40,6 @@ class ObjCContainersChecker : public Checker< check::PreStmt<CallExpr>,
   inline SymbolRef getArraySym(const Expr *E, CheckerContext &C) const {
     SVal ArrayRef = C.getState()->getSVal(E, C.getLocationContext());
     SymbolRef ArraySym = ArrayRef.getAsSymbol();
-    assert(ArraySym);
     return ArraySym;
   }
 
@@ -120,8 +119,12 @@ void ObjCContainersChecker::checkPreStmt(const CallExpr *CE,
     // Retrieve the size.
     // Find out if we saw this array symbol before and have information about it.
     const Expr *ArrayExpr = CE->getArg(0);
-    const DefinedSVal *Size =
-                            State->get<ArraySizeMap>(getArraySym(ArrayExpr, C));
+    SymbolRef ArraySym = getArraySym(ArrayExpr, C);
+    if (!ArraySym)
+      return;
+
+    const DefinedSVal *Size = State->get<ArraySizeMap>(ArraySym);
+
     if (!Size)
       return;
 
index e8166eba8dc8271fdc4d22decfeea35e936e688e..7d6c175d1fc24dea15d8ad62602401854e0616d2 100644 (file)
@@ -198,3 +198,7 @@ void TestConst(CFArrayRef A, CFIndex sIndex, void* x[]) {
   const void *s1 = CFArrayGetValueAtIndex(B, 2);
 
 }
+
+void TestNullArray() {
+  CFArrayGetValueAtIndex(0, 0);
+}