diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -228,6 +228,7 @@ -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare + -Wconditional-uninitialized ) add_compiler_flag_group(-Wformat -Wformat-security) add_cxx_compiler_flags( diff --git a/src/leveldb/CMakeLists.txt b/src/leveldb/CMakeLists.txt --- a/src/leveldb/CMakeLists.txt +++ b/src/leveldb/CMakeLists.txt @@ -16,6 +16,7 @@ -Wno-shadow -Wno-sign-compare -Wno-unused-const-variable + -Wno-conditional-uninitialized ) add_c_compiler_flags(-Wno-strict-prototypes) diff --git a/src/random.cpp b/src/random.cpp --- a/src/random.cpp +++ b/src/random.cpp @@ -119,7 +119,10 @@ // this risk. #ifdef __i386__ uint8_t ok; - uint32_t r1, r2; + // Initialize to 0 to silence a compiler warning that r1 or r2 may be used + // uninitialized. Even if rdrand fails (!ok) it will set the output to 0, + // but there is no way that the compiler could know that. + uint32_t r1 = 0, r2 = 0; for (int i = 0; i < 10; ++i) { // rdrand %eax __asm__ volatile(".byte 0x0f, 0xc7, 0xf0; setc %1" @@ -139,7 +142,7 @@ return (uint64_t(r2) << 32) | r1; #elif defined(__x86_64__) || defined(__amd64__) uint8_t ok; - uint64_t r1; + uint64_t r1 = 0; // See above why we initialize to 0. for (int i = 0; i < 10; ++i) { // rdrand %rax __asm__ volatile(".byte 0x48, 0x0f, 0xc7, 0xf0; setc %1"