From: Lenny Maiorani Date: Thu, 28 Apr 2011 19:31:12 +0000 (+0000) Subject: Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=401549d71fdbc8a566c1eb71d30825de653ea5c4;p=clang Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version of StringRef::compare() because bounded version of StringRef::compare() is going to be removed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130425 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 534b887f3b..a6a256a87b 100644 --- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -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.