[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!

llvm-svn: 282422
This commit is contained in:
Vedant Kumar 2016-09-26 17:57:13 +00:00
parent f72ac492cc
commit 5cd496ba3a
1 changed files with 6 additions and 4 deletions

View File

@ -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;
}