Prior to this commit:
bench/checkblock.cpp:41:5: warning: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage]
stream.write(&a, 1); // Prevent compaction
Prior to this commit:
bench/checkblock.cpp:41:5: warning: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage]
stream.write(&a, 1); // Prevent compaction
12 | @@ -13,10 +13,10 @@ 13 | 14 | static void Base58Encode(benchmark::State& state) 15 | { 16 | - unsigned char buff[32] = { 17 | + unsigned char buff[33] = {
A NUL terminator is unnecessary here, as the array is not interpreted as a string.
21 | @@ -22,7 +22,7 @@ static void DeserializeBlockTest(benchmark::State& state) 22 | CDataStream stream((const char*)block_bench::block413567, 23 | (const char*)&block_bench::block413567[sizeof(block_bench::block413567)], 24 | SER_NETWORK, PROTOCOL_VERSION); 25 | - char a; 26 | + char a = '\0';
ACK on this change
@laanwj Thanks for the quick review! This PR is now limited to fixing the two uninitialized values in src/bench/checkblock.cpp.
Uninitialized values are fine if they are not read?
@MarcoFalke it looks like these are read, however (well, copied and never acted on, but still technically undefined behavior).
utACK 218d915445b5936c2de1ffe1e2c97b3f3d20becc
Adding link to "Always initialize an object" (ES.20) in the C++ Core Guidelines.