QString: prevent crash in remove(pos, len)

If pos < 0, the code assumes it should count from end of string, i.e.
 pos += size(); if pos is still < 0, do nothing.

Change-Id: I5a90a082ec2833835ce0240d40a271f711a33f7e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2022-11-02 20:38:37 +02:00
parent 3916c57718
commit df82396123

View File

@ -3290,7 +3290,7 @@ QString &QString::remove(qsizetype pos, qsizetype len)
if (pos < 0) // count from end of string
pos += size();
if (pos >= size() || len <= 0)
if (size_t(pos) >= size_t(size()) || len <= 0)
return *this;
len = std::min(len, size() - pos);