diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-01-29 23:50:33 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-01-29 23:50:33 +0000 |
| commit | 632e05d8307ebfb256c64aa5c648f3e9f11d7ae9 (patch) | |
| tree | 41ddabfcef97855dc771386d1a225da560974cfb /src/ranked_match.cc | |
| parent | 1ff60ff592ead617e98578c18bed4dacc99a6ae3 (diff) | |
Fix infinite loop when comparing RankedMatches containing invalid utf8
If we had a word containing some invalid utf8, like a wrong sequence
of continuation bytes, we would infinitely loop back to the previous
valid character start.
Fixes #1157
Diffstat (limited to 'src/ranked_match.cc')
| -rw-r--r-- | src/ranked_match.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/ranked_match.cc b/src/ranked_match.cc index 341a7fbb..ad7e4cec 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -186,6 +186,7 @@ bool RankedMatch::operator<(const RankedMatch& other) const auto it1 = m_candidate.begin(), it2 = other.m_candidate.begin(); const auto end1 = m_candidate.end(), end2 = other.m_candidate.end(); + auto last1 = it1, last2 = it2; while (true) { // find next mismatch @@ -196,8 +197,8 @@ bool RankedMatch::operator<(const RankedMatch& other) const return it1 == end1 and it2 != end2; // compare codepoints - it1 = utf8::character_start(it1, m_candidate.begin()); - it2 = utf8::character_start(it2, other.m_candidate.begin()); + it1 = utf8::character_start(it1, last1); + it2 = utf8::character_start(it2, last2); const auto cp1 = utf8::read_codepoint(it1, end1); const auto cp2 = utf8::read_codepoint(it2, end2); if (cp1 != cp2) @@ -206,6 +207,7 @@ bool RankedMatch::operator<(const RankedMatch& other) const const bool low2 = iswlower((wchar_t)cp2); return low1 == low2 ? cp1 < cp2 : low1; } + last1 = it1; last2 = it2; } } |
