From: Zhongxing Xu Date: Mon, 24 Nov 2008 05:16:01 +0000 (+0000) Subject: Strings are NULL terminated. So the region size should plus one. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b89e034a7778669c4f0888d66afef4cc03fb064;p=clang Strings are NULL terminated. So the region size should plus one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59943 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 73b25955c1..99c225f5e8 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -275,7 +275,7 @@ SVal RegionStoreManager::getSizeInElements(const GRState* St, const StringLiteral* Str = SR->getStringLiteral(); // We intentionally made the size value signed because it participates in // operations with signed indices. - return NonLoc::MakeVal(getBasicVals(), Str->getByteLength(), false); + return NonLoc::MakeVal(getBasicVals(), Str->getByteLength() + 1, false); } if (const AnonTypedRegion* ATR = dyn_cast(R)) { diff --git a/test/Analysis/outofbound.c b/test/Analysis/outofbound.c index 17608ff168..6e6e8f033b 100644 --- a/test/Analysis/outofbound.c +++ b/test/Analysis/outofbound.c @@ -2,5 +2,5 @@ char f1() { char* s = "abcd"; - return s[4]; // expected-warning{{Load or store into an out-of-bound memory position.}} + return s[5]; // expected-warning{{Load or store into an out-of-bound memory position.}} }