summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-11-14 20:05:54 +0000
committerTed Kremenek <kremenek@apple.com>2011-11-14 20:05:54 +0000
commit731607fab2a573197ea7d02d3b296fec792b4079 (patch)
treed91b57b66308bf966b9422a426852770a88411c4
parentc8b47586bb293c5717036434890193e9a5ed51e4 (diff)
downloadbcm5719-llvm-731607fab2a573197ea7d02d3b296fec792b4079.tar.gz
bcm5719-llvm-731607fab2a573197ea7d02d3b296fec792b4079.zip
[analyzer;Regionstore] handle loads from StringLiteral elements for StringLiterals representing wide strings. Fixes PR 11294.
llvm-svn: 144563
-rw-r--r--clang/lib/StaticAnalyzer/Core/RegionStore.cpp6
-rw-r--r--clang/test/Analysis/misc-ps.c9
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 4b76cf1a3de..a207729be05 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -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);
}
}
diff --git a/clang/test/Analysis/misc-ps.c b/clang/test/Analysis/misc-ps.c
index 32475f0d0f2..c10037381a1 100644
--- a/clang/test/Analysis/misc-ps.c
+++ b/clang/test/Analysis/misc-ps.c
@@ -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";
+}
OpenPOWER on IntegriCloud