This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push: new f813aeead Fix -Wmaybe-uninitialized warnings on ARM/Rocky Linux builds f813aeead is described below commit f813aeead00d01482b21a4c28bdb5620b28c8aaf Author: kedeng <kdeng...@gmail.com> AuthorDate: Mon Jun 23 14:43:16 2025 +0800 Fix -Wmaybe-uninitialized warnings on ARM/Rocky Linux builds GCC on ARM-based Rocky Linux platforms emits false-positive -Wmaybe-uninitialized warnings in several locations where variables are passed to constructors without explicit initialization, even though the memory is not accessed prior to being written or used safely. This patch clarifies or explicitly initializes such variables to suppress the warnings while preserving the original logic and intent of each use. Details: 1. `log_util.cc`: The `scratch` buffers used in header/footer parsing are now explicitly zero-initialized. While they are written before use, GCC still warns due to lack of path-sensitive analysis. 2. `index-test.cc`: In the `CorruptedTrailer` test, a small `buf[3]` array is used to simulate invalid trailer content. We now use a single `rand()` call (after seeding via `SeedRandom()`) and extract 3 bytes from the result. This better aligns with the test's intent and ensures non-fixed garbage data. 3. `bloomfile-test-base.cc`: Although `key_buf` was reassigned in each loop iteration, the warning was triggered due to its declaration outside the loop. Moving its definition into the loop eliminates the warning without changing behavior. 4. `env_posix.cc`: Buffers `magic` and `file_key` are now explicitly initialized. These buffers are written to before use, but GCC emits spurious warnings otherwise. These changes make no functional modifications to the code and are purely to suppress false-positive warnings, ensuring clean builds with GCC in ARM/Rocky environments. NOTE: None of these warnings correspond to actual uninitialized memory access. The memory in question is either not accessed at all or is initialized before any such use. Change-Id: Ic6442c5b0d8087f6360916070299278fcc41d39b Reviewed-on: http://gerrit.cloudera.org:8080/23062 Tested-by: Alexey Serbin <ale...@apache.org> Reviewed-by: Alexey Serbin <ale...@apache.org> --- src/kudu/cfile/bloomfile-test-base.cc | 9 ++++----- src/kudu/cfile/index-test.cc | 15 ++++++++++++++- src/kudu/consensus/log_util.cc | 4 ++-- src/kudu/util/env_posix.cc | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/kudu/cfile/bloomfile-test-base.cc b/src/kudu/cfile/bloomfile-test-base.cc index 955fa59cc..7adaf8136 100644 --- a/src/kudu/cfile/bloomfile-test-base.cc +++ b/src/kudu/cfile/bloomfile-test-base.cc @@ -58,15 +58,14 @@ void BloomFileTestBase::SetUp() { } void BloomFileTestBase::AppendBlooms(BloomFileWriter* bfw) { - uint64_t key_buf; - Slice key_slice(reinterpret_cast<const uint8_t*>(&key_buf), - sizeof(key_buf)); - for (uint64_t i = 0; i < FLAGS_n_keys; i++) { // Shift the key left a bit so that while querying, we can // get a good mix of hits and misses while still staying within // the real key range. - key_buf = BigEndian::FromHost64(i << kKeyShift); + uint64_t key_buf = BigEndian::FromHost64(i << kKeyShift); + + Slice key_slice(reinterpret_cast<const uint8_t*>(&key_buf), + sizeof(key_buf)); ASSERT_OK_FAST(bfw->AppendKeys(&key_slice, 1)); } } diff --git a/src/kudu/cfile/index-test.cc b/src/kudu/cfile/index-test.cc index 0b61b8738..6581c1f28 100644 --- a/src/kudu/cfile/index-test.cc +++ b/src/kudu/cfile/index-test.cc @@ -16,6 +16,7 @@ // under the License. #include <cstdint> +#include <cstdlib> #include <cstdio> #include <cstring> #include <memory> @@ -40,6 +41,7 @@ #include "kudu/util/slice.h" #include "kudu/util/status.h" #include "kudu/util/test_macros.h" +#include "kudu/util/test_util.h" using std::string; using std::unique_ptr; @@ -423,9 +425,20 @@ TEST(TestIndexBlock, EmptyKeys) { // Corrupt the trailer or its size in the block and try to parse the block. TEST(TestIndexBlock, CorruptedTrailer) { + // Seed the random number generator once at the beginning of the test. + SeedRandom(); // Ensures pseudo-randomness across runs + // Data chunk is too small. { - uint8_t buf[3]; + // Generate a single random integer + int r = rand(); + + // Extract 3 bytes from the random int + uint8_t buf[3] = { + static_cast<uint8_t>(r & 0xFF), + static_cast<uint8_t>((r >> 8) & 0xFF), + static_cast<uint8_t>((r >> 16) & 0xFF) + }; Slice b(buf, sizeof(buf)); IndexBlockReader reader; const auto s = reader.Parse(b); diff --git a/src/kudu/consensus/log_util.cc b/src/kudu/consensus/log_util.cc index 59eaaddbb..d058ecec6 100644 --- a/src/kudu/consensus/log_util.cc +++ b/src/kudu/consensus/log_util.cc @@ -464,7 +464,7 @@ Status ReadableLogSegment::ReadHeader() { Status ReadableLogSegment::ReadHeaderMagicAndHeaderLength(uint32_t *len) const { - uint8_t scratch[kLogSegmentHeaderMagicAndHeaderLength]; + uint8_t scratch[kLogSegmentHeaderMagicAndHeaderLength] = {}; Slice slice(scratch, kLogSegmentHeaderMagicAndHeaderLength); RETURN_NOT_OK(file_->Read(file_->GetEncryptionHeaderSize(), slice)); RETURN_NOT_OK(ParseHeaderMagicAndHeaderLength(slice, len)); @@ -537,7 +537,7 @@ Status ReadableLogSegment::ReadFooter() { } Status ReadableLogSegment::ReadFooterMagicAndFooterLength(uint32_t *len) const { - uint8_t scratch[kLogSegmentFooterMagicAndFooterLength]; + uint8_t scratch[kLogSegmentFooterMagicAndFooterLength] = {}; Slice slice(scratch, kLogSegmentFooterMagicAndFooterLength); CHECK_GT(file_size(), kLogSegmentFooterMagicAndFooterLength); diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc index cb17c50ee..4809bc312 100644 --- a/src/kudu/util/env_posix.cc +++ b/src/kudu/util/env_posix.cc @@ -858,9 +858,9 @@ Status DoIsOnXfsFilesystem(const string& path, bool* result) { Status ReadEncryptionHeader(int fd, const string& filename, const EncryptionHeader& encryption_key, EncryptionHeader* eh) { - char magic[7]; + char magic[7] = {}; uint8_t algorithm[1] = {0}; - char file_key[32]; + char file_key[32] = {}; vector<Slice> headerv({ Slice(magic, 7), Slice(algorithm, 1), Slice(file_key, 32) }); RETURN_NOT_OK(DoReadV(fd, filename, 0, headerv, nullptr)); if (strncmp(magic, kEncryptionHeaderMagic, 7) != 0) {