@@ -100,7 +100,10 @@ static bool GetHWRand(unsigned char* ent32) {
100
100
// Not all assemblers support the rdrand instruction, write it in hex.
101
101
#ifdef __i386__
102
102
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 ;
104
107
__asm__ volatile (" .byte 0x0f, 0xc7, 0xf0;" // rdrand %eax
105
108
" .byte 0x0f, 0xc7, 0xf2;" // rdrand %edx
106
109
" setc %2" :
@@ -110,7 +113,7 @@ static bool GetHWRand(unsigned char* ent32) {
110
113
WriteLE32 (ent32 + 8 * iter + 4 , r2);
111
114
}
112
115
#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.
114
117
__asm__ volatile (" .byte 0x48, 0x0f, 0xc7, 0xf0, " // rdrand %rax
115
118
" 0x48, 0x0f, 0xc7, 0xf3, " // rdrand %rbx
116
119
" 0x48, 0x0f, 0xc7, 0xf1, " // rdrand %rcx
0 commit comments