From af6a417acb3db5a85787d14af0dea61fbbea5a6c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 3 Mar 2025 19:04:39 +0100 Subject: [PATCH] QTriangulator: make a primeForCount() precondition explicit Coverity complains that the binary search algorithm can yield high = 32, which, when passed to primeForNumBits(), will overflow prime_deltas[]. This is true, for negative 'count', or, more general, if the MSB of 'count' is set. Add a Q_ASSERT(count >= 0) to inform Coverity (and other readers of the code) that this function is only expecting non-negative arguments. Amends 4adf5e1a9ef4fe78f4b70b7462943246903f4f11, which didn't fully solve the issue, at least not as far as Coverity is concerned. Pick-to: 6.8 6.5 Coverity-Id: 11295 Task-number: QTBUG-134543 Change-Id: I994dd1d1850c6644188a9fc0b83973614dd51e6b Reviewed-by: Laszlo Agocs (cherry picked from commit 536cd1ce20a59e4daaf3a09c115f2dc5ad9cbf91) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qtriangulator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/painting/qtriangulator.cpp b/src/gui/painting/qtriangulator.cpp index df96e9f9567..17799cb0727 100644 --- a/src/gui/painting/qtriangulator.cpp +++ b/src/gui/painting/qtriangulator.cpp @@ -418,6 +418,7 @@ static inline int primeForNumBits(int numBits) static inline int primeForCount(int count) { + Q_ASSERT(count >= 0); // Q_PRE int low = 0; int high = 32; for (int i = 0; i < 5; ++i) {