]> granicus.if.org Git - clang/commitdiff
[analyzer;Regionstore] handle loads from StringLiteral elements for StringLiterals...
authorTed Kremenek <kremenek@apple.com>
Mon, 14 Nov 2011 20:05:54 +0000 (20:05 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 14 Nov 2011 20:05:54 +0000 (20:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144563 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4b76cf1a3debce85fc106f8d7def0102fad0cb90..a207729be05cc7eecc749174f9b82afa32e5c93b 100644 (file)
@@ -1046,12 +1046,12 @@ SVal RegionStoreManager::RetrieveElement(Store store,
       // clients of RetrieveElement().
       if (i < 0)
         return UndefinedVal();
-      int64_t byteLength = Str->getByteLength();
-      // Technically, only i == byteLength is guaranteed to be null.
+      int64_t length = Str->getLength();
+      // Technically, only i == length is guaranteed to be null.
       // However, such overflows should be caught before reaching this point;
       // the only time such an access would be made is if a string literal was
       // used to initialize a larger array.
-      char c = (i >= byteLength) ? '\0' : Str->getString()[i];
+      char c = (i >= length) ? '\0' : Str->getCodeUnit(i);
       return svalBuilder.makeIntVal(c, T);
     }
   }
index 32475f0d0f2b89d0212d56e489f844d989d19f23..c10037381a1f1b1b81cf053657b06dcbff04521a 100644 (file)
@@ -120,3 +120,12 @@ void barR10376675(int *x) {
     *x = fooR10376675();
   } while (0);
 }
+
+// Test accesses to wide character strings doesn't break the analyzer.
+typedef int wchar_t;
+struct rdar10385775 {
+    wchar_t *name;
+};
+void RDar10385775(struct rdar10385775* p) {
+    p->name = L"a";
+}