Fix a crash when editing cpp file

std::mismach() overload taking 3 arg assumes, that
second string is at least as long as the first one.
We don't guarantee this, as somethimes filePath2 is
empty string. Use 4 arg overload instead, which
ensure we don't exceed the valid range.

Fixes: QTCREATORBUG-24970
Change-Id: I8b7b11d124f69c7c9cb3246ee969f134fa026e08
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2020-11-30 13:09:39 +01:00
parent 1a8fdb1379
commit 448cdb7bb5

View File

@@ -108,9 +108,8 @@ bool FileIterationOrder::isValid() const
static int commonPrefixLength(const QString &filePath1, const QString &filePath2)
{
const auto mismatches = std::mismatch(filePath1.begin(),
filePath1.end(),
filePath2.begin());
const auto mismatches = std::mismatch(filePath1.begin(), filePath1.end(),
filePath2.begin(), filePath2.end());
return mismatches.first - filePath1.begin();
}