summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2025-12-04 14:44:09 +0100
committerMarc Mutz <marc.mutz@qt.io>2025-12-05 17:10:04 +0000
commitb91c23afda75b3431bfe1218cad02b25ae3446ce (patch)
tree1cfb12195d95e2973acea76b7c00df5485ac84b3
parent75461685af4a3774b0c7ef6d9451221cf700b211 (diff)
QTextEngine: fix Coverity warning about overflowing an uint
Coverity complained that the while loop being changed by this patch overflowed last_cluster from its initial ~0u value in the post-increment operation. It's correct that we overflow, but the old code wasn't wrong: unsigned overflow is well-defined as mod 2^n, n = bit-width of the type, so we overflow to zero, but then, two lines further down, unconditionally overwrite said zero again. If we overflowed, that means that last_cluster was still at ~0u, so cannot possibly have compared < that `cluster`, another uint variable, so we couldn't get into the situation that the loop continues because of 0 < cluster. So this doesn't _need_ fixing, but in the spirit of "if Coverity doesn't understand it, a human won't, either", let's improve the code nonetheless. Observe that last_cluster is being used both as the loop counter as well as to hold the value across an outer loop. Separating the two roles by introducing a dedicated loop counter shows that this is just your typical run-of-the-mill for loop, so rewrite it as such. Amends c77222c0e711d584bec880222412fc50d044005f (5.3). Pick-to: 6.10 6.8 6.5 Coverity-Id: 898027 Change-Id: I8184bddc88e24a4a6612309ae59b64b99ca4c2d7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/gui/text/qtextengine.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index ede5409b112..41d2d417133 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1746,7 +1746,7 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st
// fix up clusters so that the cluster indices will be monotonic
// and thus we never return out-of-order indices
- while (last_cluster++ < cluster && str_pos < item_length)
+ for (uint j = last_cluster; j < cluster && str_pos < item_length; ++j)
log_clusters[str_pos++] = last_glyph_pos;
last_glyph_pos = i + glyphs_shaped;
last_cluster = cluster;