From df82396123350b67c4696673eea09d3cec995ae9 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 2 Nov 2022 20:38:37 +0200 Subject: [PATCH] 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 --- src/corelib/text/qstring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 3dcb812a80..bb5c0fe4ee 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -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);