summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qunicodetools.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2025-10-20 20:53:12 +0200
committerMarc Mutz <marc.mutz@qt.io>2025-10-24 19:45:46 +0200
commit9f9da8a30cd78e51d0e50fcc2f62950ba04966e3 (patch)
tree56a719ea25cf60941ec97de12edf32de15403fd3 /src/corelib/text/qunicodetools.cpp
parent5d0a64f5c0670e40d5b7034853d2677d7a2a97a5 (diff)
Fix off-by-one in QUnicodeTools::getWhiteSpaces()
There are no space characters in Unicode outside the BMP at the moment (QUnicodeTables::MaxSeparatorCodepoint == 0x3000 at this point), but if there were, the old code would flip the QCharAttributes::whiteSpace on the low-surrogate position, not the high one, as all other functions do. Fix by using the same pattern used by the other boundary-finding functions: save the index at the start of the loop, and use the saved value when indexing into attributes[]. Amends 824180a12249e48c0e3280fec64940825ce0aa6e. Pick-to: 6.10 6.8 6.5 Change-Id: I116a5e1da6c9df5e4237073481d71efbf956f27f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qunicodetools.cpp')
-rw-r--r--src/corelib/text/qunicodetools.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp
index 14c611bdb5b..2d0b65fcc76 100644
--- a/src/corelib/text/qunicodetools.cpp
+++ b/src/corelib/text/qunicodetools.cpp
@@ -1124,6 +1124,7 @@ static void getLineBreaks(const char16_t *string, qsizetype len, QCharAttributes
static void getWhiteSpaces(const char16_t *string, qsizetype len, QCharAttributes *attributes)
{
for (qsizetype i = 0; i != len; ++i) {
+ const auto pos = i;
uint ucs4 = string[i];
if (QChar::isHighSurrogate(ucs4) && i + 1 != len) {
ushort low = string[i + 1];
@@ -1134,7 +1135,7 @@ static void getWhiteSpaces(const char16_t *string, qsizetype len, QCharAttribute
}
if (Q_UNLIKELY(QChar::isSpace(ucs4)))
- attributes[i].whiteSpace = true;
+ attributes[pos].whiteSpace = true;
}
}