Commit f5e289d
committed
Fix constant integer overflow in irk_rand_uint32_vec
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.1 parent 5023828 commit f5e289d
2 files changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1981 | 1981 | | |
1982 | 1982 | | |
1983 | 1983 | | |
1984 | | - | |
| 1984 | + | |
1985 | 1985 | | |
1986 | 1986 | | |
1987 | 1987 | | |
| |||
0 commit comments