On Tue, 21 Jan 2014, Dave Jones wrote: > random.c:57:16: warning: Division by zero > if (!temp) r %= temp; > ~~^~~~~~~ > random.c:62:26: warning: Division by zero > if (!temp) r |= rand() % temp; > ~~~~~~~^~~~~~ > > Vince, want to send a follow-up fix ? Yes, brown-paper bag time. Never trust "it compiles and runs" as testing for a bug that only shows up 1 in 4 billion times anyway. I've copied the code into a test harness and actually ran it with code that returns zero more often to verify it works (after hacking things so gcc didn't "helpfully" optimize the zero generating code away). --- The previous fix to the divide-by-zero bug in random/taviso() (fea56c28830f "fix divide by zero in random/taviso()") had the zero-checks inverted. This meant the old div-by-zero bug was still there, and worse, it meant that the number being generated always had 32-bits of zeros in the bottom half on a 64-bit machine. Signed-off-by: Vince Weaver <vincent.weaver@xxxxxxxxx> diff --git a/random.c b/random.c index 75fa868..38ed22f 100644 --- a/random.c +++ b/random.c @@ -54,12 +54,12 @@ static unsigned long taviso(void) case 1: temp = rand(); r = rand(); - if (!temp) r %= temp; + if (temp) r %= temp; #if __WORDSIZE == 64 r <<= 32; temp = rand(); - if (!temp) r |= rand() % temp; + if (temp) r |= rand() % temp; #endif break; -- To unsubscribe from this list: send the line "unsubscribe trinity" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html