Commit d0589708 authored by deuce's avatar deuce
Browse files

Remove potential for division by zero by moving the limit calculation to

after test of n.

Remove potential for undefined behaviour (INT_MIN-1) by making limit an
unsigned long.
parent 14cdd775
......@@ -322,12 +322,14 @@ void DLLCALL xp_randomize(void)
long DLLCALL xp_random(int n)
long curr;
long limit=((1U<<((sizeof(long)*CHAR_BIT)-1)) / n) * n - 1;
long curr;
unsigned long limit;
limit = ((1U<<((sizeof(long)*CHAR_BIT)-1)) / n) * n - 1;
while(1) {
if(curr <= limit)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment