diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index c7a601fe5e..d3b72c734d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -3279,11 +3279,11 @@ QString &QString::remove(qsizetype pos, qsizetype len) { if (pos < 0) // count from end of string pos += size(); + if (size_t(pos) >= size_t(size())) { // range problems - } else if (len >= size() - pos) { - resize(pos); // truncate } else if (len > 0) { + len = std::min(len, size() - pos); detach(); d->erase(d.begin() + pos, len); d.data()[d.size] = u'\0';