From 4bfce80f1def3b5e8a8dd5f8b453012babc8bf37 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Aug 2022 09:43:46 +0200 Subject: [PATCH] QUnicodeTools: fix types used around th_next_cell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Libthai's th_next_cell takes and returns lengths as size_t. - pass size_t, not qsizetype (the value can never be negative) - receive size_t, don't cast to uint As a drive-by, scope variables tighter. Task-number: QTBUG-103531 Change-Id: Ib1eeb1f0e8974ee8b0f88d080d06136b307c324f Reviewed-by: Lars Knoll Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit ea1e005cb18cbd4fe9ceda725aac47bbfb068389) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qunicodetools.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qunicodetools.cpp b/src/corelib/text/qunicodetools.cpp index beef159daab..0d9935b1427 100644 --- a/src/corelib/text/qunicodetools.cpp +++ b/src/corelib/text/qunicodetools.cpp @@ -1445,7 +1445,7 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt int *break_positions = nullptr; int brp[128]; int brp_size = 0; - qsizetype numbreaks, i, j, cell_length; + qsizetype numbreaks, i; struct thcell_t tis_cell; if (!init_libthai()) @@ -1494,11 +1494,12 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt /* manage grapheme boundaries */ i = 0; while (i < len) { - cell_length = static_cast(th_next_cell(reinterpret_cast(cstr) + i, len - i, &tis_cell, true)); + size_t cell_length = th_next_cell(reinterpret_cast(cstr) + i, + size_t(len - i), &tis_cell, true); attributes[i].graphemeBoundary = true; - for (j = 1; j < cell_length; j++) + for (size_t j = 1; j < cell_length; ++j) attributes[i + j].graphemeBoundary = false; i += cell_length;