summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-05-12 09:41:35 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-06-11 22:04:04 +0000
commitf9b867216ba2728ff993020599f5062e2f023de1 (patch)
tree8c4624099a93adb32de2b4e0644e28a50614a219 /src/corelib/text/qstring.cpp
parente6457d9b600e26419bfdb5eea1acb62cf96b88e3 (diff)
String API Symmetry: test for indexOf with large negative offset
Small change needed to make QString_char16 and QString_QChar return -1 in this case, but other combinations already returns -1. [ChangeLog][QtCore][Behavior Change] QString::indexOf(QChar) and QString::indexOf(char16_t) now treat a negative start-position, from, bigger than the string's size as invalid. It previously clipped such start-positions to the start of the string, inconsistently with other QString indexOf overloads. Change-Id: Ic56c8a558bf40a94845c649647db569892d4df02 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 89abbcbff3..3e4d95188d 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -10157,6 +10157,8 @@ char16_t valueTypeToUtf16<char>(char t)
static inline qsizetype qFindChar(QStringView str, QChar ch, qsizetype from, Qt::CaseSensitivity cs) noexcept
{
+ if (-from > str.size())
+ return -1;
if (from < 0)
from = qMax(from + str.size(), qsizetype(0));
if (from < str.size()) {