QTriangulator: make primeForCount() safer

Move all the helpers into the function so nothing else can call them
(out of contract).

As a drive-by, adjust the comment to mention this is Qt 5 QHash
snippets; Q6Hash is different these days.

Pick-to: 6.8 6.5
Coverity-Id: 11295
Change-Id: Id1a23030e325076d81592e351dfe804742a21a87
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 0a9d5bd4767d2dc5900707e23790d79e6f5e0bd0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-03 19:19:16 +01:00 committed by Qt Cherry-pick Bot
parent 663464036a
commit 6274df7db5

View File

@ -404,21 +404,21 @@ T QMaxHeap<T>::pop()
// QInt64Hash // // QInt64Hash //
//============================================================================// //============================================================================//
// Copied from qhash.cpp
static const uchar prime_deltas[] = {
0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3,
1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0
};
// Copied from qhash.cpp
static inline int primeForNumBits(int numBits)
{
return (1 << numBits) + prime_deltas[numBits];
}
static inline int primeForCount(int count) static inline int primeForCount(int count)
{ {
Q_ASSERT(count >= 0); // Q_PRE Q_ASSERT(count >= 0); // Q_PRE
// Copied from Qt 5 qhash.cpp
constexpr auto primeForNumBits = [](int numBits) -> int
{
constexpr uchar prime_deltas[] = {
0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3,
1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0
};
return (1 << numBits) + prime_deltas[numBits];
};
int low = 0; int low = 0;
int high = 32; int high = 32;
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {