From: Vedant Kumar Date: Mon, 26 Sep 2016 17:57:13 +0000 (+0000) Subject: [llvm-cov] Silence a warning from the MSVC runtime (NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64f3b51479d689f9f313d5ab4b621cd31376049f;p=llvm [llvm-cov] Silence a warning from the MSVC runtime (NFC) Rework getLongestCommonPrefixLen() so that it doesn't access string null terminators. The old version with std::mismatch would do this: | v Strings[0] = ['a', nil] Strings[1] = ['a', 'a', nil] ^ | This should silence a warning from the MSVC runtime (PR30515). As before, I tested this out by preparing a coverage report for FileCheck. Thanks to Yaron Keren for the report! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282422 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-cov/CoverageReport.cpp b/tools/llvm-cov/CoverageReport.cpp index 24d7c661aad..5a56579149a 100644 --- a/tools/llvm-cov/CoverageReport.cpp +++ b/tools/llvm-cov/CoverageReport.cpp @@ -123,10 +123,12 @@ raw_ostream::Colors determineCoveragePercentageColor(const T &Info) { unsigned getLongestCommonPrefixLen(ArrayRef Strings) { unsigned LCP = Strings[0].size(); for (unsigned I = 1, E = Strings.size(); LCP > 0 && I < E; ++I) { - auto Mismatch = - std::mismatch(Strings[0].begin(), Strings[0].end(), Strings[I].begin()) - .first; - LCP = std::min(LCP, (unsigned)std::distance(Strings[0].begin(), Mismatch)); + unsigned Cursor; + StringRef S = Strings[I]; + for (Cursor = 0; Cursor < LCP && Cursor < S.size(); ++Cursor) + if (Strings[0][Cursor] != S[Cursor]) + break; + LCP = std::min(LCP, Cursor); } return LCP; }