@@ -100,7 +100,10 @@ static bool GetHWRand(unsigned char* ent32) {
100100 // Not all assemblers support the rdrand instruction, write it in hex.
101101#ifdef __i386__
102102 for (int iter = 0 ; iter < 4 ; ++iter) {
103- uint32_t r1, r2;
103+ // Initialize to 0 to silence a compiler warning that r1 or r2 may be used
104+ // uninitialized. Even if rdrand fails (!ok) it will set the output to 0,
105+ // but there is no way that the compiler could know that.
106+ uint32_t r1 = 0 , r2 = 0 ;
104107 __asm__ volatile (" .byte 0x0f, 0xc7, 0xf0;" // rdrand %eax
105108 " .byte 0x0f, 0xc7, 0xf2;" // rdrand %edx
106109 " setc %2" :
@@ -110,7 +113,7 @@ static bool GetHWRand(unsigned char* ent32) {
110113 WriteLE32 (ent32 + 8 * iter + 4 , r2);
111114 }
112115#else
113- uint64_t r1, r2, r3, r4;
116+ uint64_t r1 = 0 , r2 = 0 , r3 = 0 , r4 = 0 ; // See above why we initialize to 0.
114117 __asm__ volatile (" .byte 0x48, 0x0f, 0xc7, 0xf0, " // rdrand %rax
115118 " 0x48, 0x0f, 0xc7, 0xf3, " // rdrand %rbx
116119 " 0x48, 0x0f, 0xc7, 0xf1, " // rdrand %rcx
0 commit comments