From: Derrick Lyndon Pallas Date: Mon, 22 Apr 2019 21:13:52 +0000 (+0000) Subject: Fix uninitialized use of scatter_unit_uX due to padding X-Git-Tag: v5.2.0^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a1b02bc10547dbb8f0e5c0fccb7373fa55d0979;p=thirdparty%2Fvectorscan.git Fix uninitialized use of scatter_unit_uX due to padding These non-packed structures are placed into a std::vector. Later, they contents of the vector are memcpy'd and the CRC of this space is taken. Some compilers will zero the struct padding but GCC8.2 with -O2 at least will not. This means that the CRC is based on uninitialized memory. Since it is expected that these bytes will be memcpy'd, zero in place once they're in the std::vector. Found by Valgrind. Q.v. Issue #148 --- diff --git a/src/util/multibit_build.cpp b/src/util/multibit_build.cpp index ad6a0d6a..67bb9ec7 100644 --- a/src/util/multibit_build.cpp +++ b/src/util/multibit_build.cpp @@ -192,11 +192,11 @@ vector mmbBuildSparseIterator(const vector &bits, template static void add_scatter(vector *out, u32 offset, u64a mask) { - T su; + out->emplace_back(); + T &su = out->back(); memset(&su, 0, sizeof(su)); su.offset = offset; su.val = mask; - out->push_back(su); DEBUG_PRINTF("add %llu at offset %u\n", mask, offset); }