Skip to content

Fix(rand): UB on different platform#525

Merged
alanminko merged 1 commit into
berkeley-abc:masterfrom
wjrforcyber:rand_fix
Jul 2, 2026
Merged

Fix(rand): UB on different platform#525
alanminko merged 1 commit into
berkeley-abc:masterfrom
wjrforcyber:rand_fix

Conversation

@wjrforcyber

Copy link
Copy Markdown
Contributor

This idiom combines two 15-bit rand() samples and is only safe when RAND_MAX == 32767 (MSVC/Windows, reference). On glibc and Apple libc, RAND_MAX == 2147483647 (reference), so rand() << 15 overflows signed int (UB) and
the result goes negative sometimes. The negative value is passed to Vec_WecEntry, tripping assert(i >= 0).

Signed-off-by: JingrenWang <wjrforcyber@163.com>
@alanminko alanminko merged commit 523af52 into berkeley-abc:master Jul 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants