From: Ted Kremenek Date: Mon, 14 Nov 2011 20:05:54 +0000 (+0000) Subject: [analyzer;Regionstore] handle loads from StringLiteral elements for StringLiterals... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=729aa06b9d190ce01eccb7108415e698fc52f6f4;p=clang [analyzer;Regionstore] handle loads from StringLiteral elements for StringLiterals representing wide strings. Fixes PR 11294. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144563 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp index 4b76cf1a3d..a207729be0 100644 --- a/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/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/test/Analysis/misc-ps.c b/test/Analysis/misc-ps.c index 32475f0d0f..c10037381a 100644 --- a/test/Analysis/misc-ps.c +++ b/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"; +}