From 4c8f33640157df124f0cec6ff993445bf5b709db Mon Sep 17 00:00:00 2001 From: Prashant D Date: Fri, 3 Nov 2017 14:32:00 -0700 Subject: [PATCH] util: Fix coverity issues Summary: util/concurrent_arena.h: CID 1396145 (#1 of 1): Uninitialized pointer field (UNINIT_CTOR) 2. uninit_member: Non-static class member free_begin_ is not initialized in this constructor nor in any functions that it calls. 94 Shard() : allocated_and_unused_(0) {} util/dynamic_bloom.cc: 1. Condition hash_func == NULL, taking true branch. CID 1322821 (#1 of 1): Uninitialized pointer field (UNINIT_CTOR) 3. uninit_member: Non-static class member data_ is not initialized in this constructor nor in any functions that it calls. 47 hash_func_(hash_func == nullptr ? &BloomHash : hash_func) {} 48 util/file_reader_writer.h: 204 private: 205 AlignedBuffer buffer_; member_not_init_in_gen_ctor: The compiler-generated constructor for this class does not initialize buffer_offset_. 206 uint64_t buffer_offset_; CID 1418246 (#1 of 1): Uninitialized scalar field (UNINIT_CTOR) member_not_init_in_gen_ctor: The compiler-generated constructor for this class does not initialize buffer_len_. 207 size_t buffer_len_; 208}; util/thread_local.cc: 341#endif CID 1322795 (#1 of 1): Uninitialized scalar field (UNINIT_CTOR) 3. uninit_member: Non-static class member pthread_key_ is not initialized in this constructor nor in any functions that it calls. 342} 40struct ThreadData { 2. uninit_member: Non-static class member next is not initialized in this constructor nor in any functions that it calls. CID 1400668 (#1 of 1): Uninitialized pointer field (UNINIT_CTOR) 4. uninit_member: Non-static class member prev is not initialized in this constructor nor in any functions that it calls. 41 explicit ThreadData(ThreadLocalPtr::StaticMeta* _inst) : entries(), inst(_inst) {} 42 std::vector entries; 1. member_decl: Class member declaration for next. 43 ThreadData* next; 3. member_decl: Class member declaration for prev. 44 ThreadData* prev; 45 ThreadLocalPtr::StaticMeta* inst; 46}; Closes https://github.com/facebook/rocksdb/pull/3123 Differential Revision: D6233566 Pulled By: sagar0 fbshipit-source-id: aa2068790ea69787a0035c0db39d59b0c25108db --- util/concurrent_arena.h | 2 +- util/dynamic_bloom.cc | 3 ++- util/file_reader_writer.h | 1 + util/thread_local.cc | 11 +++++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/util/concurrent_arena.h b/util/concurrent_arena.h index 1ab88c7ff..a6191100f 100644 --- a/util/concurrent_arena.h +++ b/util/concurrent_arena.h @@ -91,7 +91,7 @@ class ConcurrentArena : public Allocator { char* free_begin_; std::atomic allocated_and_unused_; - Shard() : allocated_and_unused_(0) {} + Shard() : free_begin_(nullptr), allocated_and_unused_(0) {} }; #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL diff --git a/util/dynamic_bloom.cc b/util/dynamic_bloom.cc index 7c296cb4d..1dabf2968 100644 --- a/util/dynamic_bloom.cc +++ b/util/dynamic_bloom.cc @@ -44,7 +44,8 @@ DynamicBloom::DynamicBloom(uint32_t num_probes, : kTotalBits(0), kNumBlocks(0), kNumProbes(num_probes), - hash_func_(hash_func == nullptr ? &BloomHash : hash_func) {} + hash_func_(hash_func == nullptr ? &BloomHash : hash_func), + data_(0) {} void DynamicBloom::SetRawData(unsigned char* raw_data, uint32_t total_bits, uint32_t num_blocks) { diff --git a/util/file_reader_writer.h b/util/file_reader_writer.h index 41bf6a309..9bc3b9437 100644 --- a/util/file_reader_writer.h +++ b/util/file_reader_writer.h @@ -201,6 +201,7 @@ class WritableFileWriter { class FilePrefetchBuffer { public: + FilePrefetchBuffer() : buffer_offset_(0), buffer_len_(0) {} Status Prefetch(RandomAccessFileReader* reader, uint64_t offset, size_t n); bool TryReadFromCache(uint64_t offset, size_t n, Slice* result) const; diff --git a/util/thread_local.cc b/util/thread_local.cc index 41f656b61..5972defce 100644 --- a/util/thread_local.cc +++ b/util/thread_local.cc @@ -38,7 +38,11 @@ class StaticMeta; // | thread 3 | void* | void* | void* | <- ThreadData // --------------------------------------------------- struct ThreadData { - explicit ThreadData(ThreadLocalPtr::StaticMeta* _inst) : entries(), inst(_inst) {} + explicit ThreadData(ThreadLocalPtr::StaticMeta* _inst) + : entries(), + next(nullptr), + prev(nullptr), + inst(_inst) {} std::vector entries; ThreadData* next; ThreadData* prev; @@ -300,7 +304,10 @@ void ThreadLocalPtr::StaticMeta::OnThreadExit(void* ptr) { delete tls; } -ThreadLocalPtr::StaticMeta::StaticMeta() : next_instance_id_(0), head_(this) { +ThreadLocalPtr::StaticMeta::StaticMeta() + : next_instance_id_(0), + head_(this), + pthread_key_(0) { if (pthread_key_create(&pthread_key_, &OnThreadExit) != 0) { abort(); }