]> granicus.if.org Git - clang/commitdiff
Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version...
authorLenny Maiorani <lenny@colorado.edu>
Thu, 28 Apr 2011 19:31:12 +0000 (19:31 +0000)
committerLenny Maiorani <lenny@colorado.edu>
Thu, 28 Apr 2011 19:31:12 +0000 (19:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130425 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/CStringChecker.cpp

index 534b887f3b26c3148bd05ddf3709cd6dbbc3051f..a6a256a87bcf1330ecc5fa887203d023582e9569 100644 (file)
@@ -1190,7 +1190,14 @@ void CStringChecker::evalStrcmpCommon(CheckerContext &C, const CallExpr *CE,
       // For now, give up.
       return;
     } else {
-      result = s1StrRef.compare(s2StrRef, (size_t)lenInt.getLimitedValue());
+      // Create substrings of each to compare the prefix.
+      llvm::StringRef s1SubStr = 
+        s1StrRef.substr(0, (size_t)lenInt.getLimitedValue());
+      llvm::StringRef s2SubStr = 
+        s2StrRef.substr(0, (size_t)lenInt.getLimitedValue());
+
+      // Compare the substrings.
+      result = s1SubStr.compare(s2SubStr);
     }
   } else {
     // Compare string 1 to string 2 the same way strcmp() does.