diff options
| author | Wladimir J. van der Laan <[email protected]> | 2020-05-06 13:49:43 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2020-05-06 13:49:49 +0200 |
| commit | 6621be53517d69ab855cee4a5978a44d6a133ba3 (patch) | |
| tree | 8a1dd92ff8f851a11a5a8b2e092833eb95f78d73 /src | |
| parent | Merge #18854: doc: Fix typo in Coin doxygen comment (diff) | |
| parent | build: warn on potentially uninitialized reads (diff) | |
| download | discoin-6621be53517d69ab855cee4a5978a44d6a133ba3.tar.xz discoin-6621be53517d69ab855cee4a5978a44d6a133ba3.zip | |
Merge #18843: build: warn on potentially uninitialized reads
71f183a49b714a28622277fa668d8f9f3dac0aae build: warn on potentially uninitialized reads (Vasil Dimov)
Pull request description:
* Enable `conditional-uninitialized` warning class to show potentially uninitialized
reads.
* Fix the sole such warning in Bitcoin Core in `GetRdRand()`: `r1` would be
set to `0` on `rdrand` failure, so initializing it to `0` is a non-functional
change.
ACKs for top commit:
practicalswift:
ACK 71f183a49b714a28622277fa668d8f9f3dac0aae
laanwj:
ACK 71f183a49b714a28622277fa668d8f9f3dac0aae
Tree-SHA512: 2c1d8caacd86424b16a9d92e5df19e0bedb51ae111eecad7e3bfa46447bc88e5fff1f32dacf6c4a28257ebb3d87e79f80f074ce2c523ce08b1a0c0a67ab44204
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.leveldb.include | 2 | ||||
| -rw-r--r-- | src/random.cpp | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/Makefile.leveldb.include b/src/Makefile.leveldb.include index 04b53471e..79ff72ca8 100644 --- a/src/Makefile.leveldb.include +++ b/src/Makefile.leveldb.include @@ -36,7 +36,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX endif leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS) -leveldb_libleveldb_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) +leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized, $(AM_CXXFLAGS)) $(PIE_FLAGS) leveldb_libleveldb_a_SOURCES= leveldb_libleveldb_a_SOURCES += leveldb/port/port_stdcxx.h diff --git a/src/random.cpp b/src/random.cpp index b408b1e13..5b8782d1c 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -116,7 +116,10 @@ static uint64_t GetRdRand() noexcept // RdRand may very rarely fail. Invoke it up to 10 times in a loop to reduce 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) { __asm__ volatile (".byte 0x0f, 0xc7, 0xf0; setc %1" : "=a"(r1), "=q"(ok) :: "cc"); // rdrand %eax if (ok) break; @@ -128,7 +131,7 @@ static uint64_t GetRdRand() noexcept 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) { __asm__ volatile (".byte 0x48, 0x0f, 0xc7, 0xf0; setc %1" : "=a"(r1), "=q"(ok) :: "cc"); // rdrand %rax if (ok) break; |