Skip to content

Commit

Permalink
[llvm-cov] Silence a warning from the MSVC runtime (NFC)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vedantk committed Sep 26, 2016
1 parent c9e7be5 commit 64f3b51
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tools/llvm-cov/CoverageReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
unsigned getLongestCommonPrefixLen(ArrayRef<std::string> 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;
}
Expand Down

0 comments on commit 64f3b51

Please sign in to comment.