]> granicus.if.org Git - clang/commitdiff
Teach RegionStore not to symbolic array values whose indices it cannot reason about.
authorTed Kremenek <kremenek@apple.com>
Thu, 19 May 2011 23:37:58 +0000 (23:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 19 May 2011 23:37:58 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131702 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/misc-ps-region-store.cpp

index fe17773fc72057001ab42f45abf0e194460ca369..d0d8f601f071e74a59fe51051ec8c12e26c90b83 100644 (file)
@@ -1063,6 +1063,11 @@ SVal RegionStoreManager::RetrieveElement(Store store,
   //   return *y;
   // FIXME: This is a hack, and doesn't do anything really intelligent yet.
   const RegionRawOffset &O = R->getAsArrayOffset();
+  
+  // If we cannot reason about the offset, return an unknown value.
+  if (!O.getRegion())
+    return UnknownVal();
+  
   if (const TypedRegion *baseR = dyn_cast_or_null<TypedRegion>(O.getRegion())) {
     QualType baseT = baseR->getValueType();
     if (baseT->isScalarType()) {
index b122bffaaec0e797e185d620544d06e13c7f2f05..795935959628ae1a0f58dd5d88b42c8da45c8438 100644 (file)
@@ -395,3 +395,22 @@ unsigned test_invalidate_in_ctor_new() {
   return x; // no-warning
 }
 
+// Test assigning into a symbolic offset.
+struct TestAssignIntoSymbolicOffset {
+  int **stuff[100];
+  void test(int x, int y);
+};
+
+void TestAssignIntoSymbolicOffset::test(int x, int y) {
+  x--;
+  if (x > 8 || x < 0)
+    return;
+  if (stuff[x])
+    return;
+  if (!stuff[x]) {
+    stuff[x] = new int*[y+1];
+    // Previously triggered a null dereference.
+    stuff[x][y] = 0; // no-warning
+  }
+}
+