pcg-c icon indicating copy to clipboard operation
pcg-c copied to clipboard

Undefined behavior: Upper bound of zero

Open 48656c6c6f opened this issue 5 years ago • 1 comments

When a function such as pcg_setseq_64_xsh_rr_32_boundedrand_r is called with a bound of 0 and bound is the denominator of a modulus operation, the result is undefined behavior -- possibly a division by zero error.

Such functions should check for and return zero in such cases to avoid undefined behavior.

48656c6c6f avatar Jan 19 '20 11:01 48656c6c6f

As an aside, these functions can be optimized to require just one division instead of two. @imneme knows how!

lemire avatar Jan 19 '20 19:01 lemire