From 3e843c0bc1afb436a27198ebdd8eb57a2a48bc28 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Fri, 10 Jan 2020 15:50:45 -0800 Subject: [PATCH] Enable -Werror=conditional-uninitialized if available And fix two trivial local violations - initialized to the empty or failing value, respectively. Note, in the current code these are false positives as the called functions do set the value in all cases, but these initializations remove the reliance on that external property. --- CMakeLists.txt | 7 +++++++ db/corruption_test.cc | 2 +- db/version_set.cc | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be41ba4..01e0d0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,6 +264,13 @@ if(BUILD_SHARED_LIBS) ) endif(BUILD_SHARED_LIBS) +check_cxx_compiler_flag(-Werror=conditional-uninitialized HAVE_CONDITIONAL_UNINITIALIZED) +if(HAVE_CONDITIONAL_UNINITIALIZED) + target_compile_options(leveldb + PUBLIC + -Werror=conditional-uninitialized) +endif(HAVE_CONDITIONAL_UNINITIALIZED) + if(HAVE_CLANG_THREAD_SAFETY) target_compile_options(leveldb PUBLIC diff --git a/db/corruption_test.cc b/db/corruption_test.cc index b22f9e7..4fdbfad 100644 --- a/db/corruption_test.cc +++ b/db/corruption_test.cc @@ -157,7 +157,7 @@ class CorruptionTest : public testing::Test { int Property(const std::string& name) { std::string property; - int result; + int result = -1; if (db_->GetProperty(name, &property) && sscanf(property.c_str(), "%d", &result) == 1) { return result; diff --git a/db/version_set.cc b/db/version_set.cc index 2d5e51a..1824e87 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -994,7 +994,7 @@ bool VersionSet::ReuseManifest(const std::string& dscname, } FileType manifest_type; uint64_t manifest_number; - uint64_t manifest_size; + uint64_t manifest_size = 0; if (!ParseFileName(dscbase, &manifest_number, &manifest_type) || manifest_type != kDescriptorFile || !env_->GetFileSize(dscname, &manifest_size).ok() ||