Fix constant integer overflow in irk_rand_uint32_vec - #156
Open
antonwolfy wants to merge 1 commit into
Open
Conversation
Declare the shift variable as npy_uint32 instead of npy_int32. The right-hand side ((npy_uint32)INT_MAX + 1) equals 2**31, which does not fit in a signed 32-bit integer and wrapped to INT32_MIN when stored. All downstream uses (lo - shift, hi - shift + 1U, res[i] += shift) already operate on the unsigned bit pattern via modulo-2**32 arithmetic, so behavior is bit-for-bit identical. This removes the Coverity INTEGER_OVERFLOW finding (CID 652701) and the out-of-range signed conversion it relied on.
antonwolfy
requested review from
jharlow-intel,
ndgrigorian,
vlad-perevezentsev and
xaleryb
as code owners
August 10, 2026 11:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Coverity
INTEGER_OVERFLOWinirk_rand_uint32_vecinmkl_random/src/mkl_distributions.cpp.The
shiftvariable was declared asnpy_int32, but its initializer:evaluates to
2**31 = 2147483648, which does not fit in a signed 32-bit integer. Storing it wrapped toINT32_MIN— an out-of-range signed conversion that Coverity flags as an overflowed constant.Fix
Declare
shiftasnpy_uint32. Both2**31and2**31 + 1(theif (lo) shift++;case) fit in an unsigned 32-bit integer, so the overflow disappears.