From 4f12d49daf73488deec2befe99f38eecdc59b436 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 21 Aug 2018 16:28:41 -0700 Subject: [PATCH] Suppress clang analyzer error (#4299) Summary: Suppress multiple clang-analyzer error. All of them are clang false-positive. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4299 Differential Revision: D9430740 Pulled By: yiwu-arbug fbshipit-source-id: fbdd575bdc214d124826d61d35a117995c509279 --- memtable/hash_cuckoo_rep.cc | 1 + util/threadpool_imp.cc | 14 +++++-------- utilities/document/document_db_test.cc | 2 ++ utilities/transactions/transaction_test.cc | 2 ++ utilities/transactions/transaction_test.h | 21 ++++++++++++------- .../write_prepared_transaction_test.cc | 7 +++++++ .../write_unprepared_transaction_test.cc | 2 +- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/memtable/hash_cuckoo_rep.cc b/memtable/hash_cuckoo_rep.cc index 39078633f..aa6e3dbf3 100644 --- a/memtable/hash_cuckoo_rep.cc +++ b/memtable/hash_cuckoo_rep.cc @@ -408,6 +408,7 @@ bool HashCuckooRep::QuickInsert(const char* internal_key, const Slice& user_key, const auto bucket_user_key = UserKey(stored_key); if (bucket_user_key.compare(user_key) == 0) { cuckoo_bucket_id = bucket_ids[hid]; + assert(cuckoo_bucket_id != -1); break; } } diff --git a/util/threadpool_imp.cc b/util/threadpool_imp.cc index 3b1f762b8..d850b7c9e 100644 --- a/util/threadpool_imp.cc +++ b/util/threadpool_imp.cc @@ -469,16 +469,12 @@ void ThreadPoolImpl::SubmitJob(std::function&& job) { void ThreadPoolImpl::Schedule(void(*function)(void* arg1), void* arg, void* tag, void(*unschedFunction)(void* arg)) { - - std::function fn = [arg, function] { function(arg); }; - - std::function unfn; - if (unschedFunction != nullptr) { - auto uf = [arg, unschedFunction] { unschedFunction(arg); }; - unfn = std::move(uf); + if (unschedFunction == nullptr) { + impl_->Submit(std::bind(function, arg), std::function(), tag); + } else { + impl_->Submit(std::bind(function, arg), std::bind(unschedFunction, arg), + tag); } - - impl_->Submit(std::move(fn), std::move(unfn), tag); } int ThreadPoolImpl::UnSchedule(void* arg) { diff --git a/utilities/document/document_db_test.cc b/utilities/document/document_db_test.cc index 652f1e455..3ee560db1 100644 --- a/utilities/document/document_db_test.cc +++ b/utilities/document/document_db_test.cc @@ -75,8 +75,10 @@ TEST_F(DocumentDBTest, SimpleQueryTest) { ASSERT_OK(DocumentDB::Open(options, dbname_, {}, &db_)); CreateIndexes({index}); delete db_; + db_ = nullptr; // now there is index present ASSERT_OK(DocumentDB::Open(options, dbname_, {index}, &db_)); + assert(db_ != nullptr); delete index.description; std::vector json_objects = { diff --git a/utilities/transactions/transaction_test.cc b/utilities/transactions/transaction_test.cc index 44c6e3596..bb1c55652 100644 --- a/utilities/transactions/transaction_test.cc +++ b/utilities/transactions/transaction_test.cc @@ -796,6 +796,7 @@ TEST_P(TransactionTest, LogMarkLeakTest) { WriteOptions write_options; options.write_buffer_size = 1024; ASSERT_OK(ReOpenNoDelete()); + assert(db != nullptr); Random rnd(47); std::vector txns; DBImpl* db_impl = reinterpret_cast(db->GetRootDB()); @@ -1254,6 +1255,7 @@ TEST_P(TransactionTest, PersistentTwoPhaseTransactionTest) { reinterpret_cast(db)->TEST_Crash(); s = ReOpenNoDelete(); ASSERT_OK(s); + assert(db != nullptr); db_impl = reinterpret_cast(db->GetRootDB()); // find trans in list of prepared transactions diff --git a/utilities/transactions/transaction_test.h b/utilities/transactions/transaction_test.h index d024cecb2..cdc014acb 100644 --- a/utilities/transactions/transaction_test.h +++ b/utilities/transactions/transaction_test.h @@ -100,6 +100,7 @@ class TransactionTestBase : public ::testing::Test { } else { s = OpenWithStackableDB(); } + assert(!s.ok() || db != nullptr); return s; } @@ -121,6 +122,7 @@ class TransactionTestBase : public ::testing::Test { } else { s = OpenWithStackableDB(cfs, handles); } + assert(db != nullptr); return s; } @@ -134,6 +136,7 @@ class TransactionTestBase : public ::testing::Test { } else { s = OpenWithStackableDB(); } + assert(db != nullptr); return s; } @@ -184,15 +187,17 @@ class TransactionTestBase : public ::testing::Test { txn_db_options.write_policy == WRITE_PREPARED; Status s = DBImpl::Open(options_copy, dbname, column_families, &handles, &root_db, use_seq_per_batch, use_batch_per_txn); - StackableDB* stackable_db = new StackableDB(root_db); - if (s.ok()) { - assert(root_db != nullptr); - assert(handles.size() == 1); - s = TransactionDB::WrapStackableDB(stackable_db, txn_db_options, - compaction_enabled_cf_indices, handles, - &db); - delete handles[0]; + if (!s.ok()) { + delete root_db; + return s; } + StackableDB* stackable_db = new StackableDB(root_db); + assert(root_db != nullptr); + assert(handles.size() == 1); + s = TransactionDB::WrapStackableDB(stackable_db, txn_db_options, + compaction_enabled_cf_indices, handles, + &db); + delete handles[0]; if (!s.ok()) { delete stackable_db; // just in case it was not deleted (and not set to nullptr). diff --git a/utilities/transactions/write_prepared_transaction_test.cc b/utilities/transactions/write_prepared_transaction_test.cc index 391d58def..391b459b2 100644 --- a/utilities/transactions/write_prepared_transaction_test.cc +++ b/utilities/transactions/write_prepared_transaction_test.cc @@ -1015,6 +1015,7 @@ TEST_P(WritePreparedTransactionTest, AdvanceMaxEvictedSeqWithDuplicatesTest) { wp_db->db_impl_->FlushWAL(true); wp_db->TEST_Crash(); ReOpenNoDelete(); + assert(db != nullptr); wp_db = dynamic_cast(db); wp_db->AdvanceMaxEvictedSeq(0, new_max); s = db->Get(ropt, db->DefaultColumnFamily(), "key", &pinnable_val); @@ -1146,6 +1147,7 @@ TEST_P(SeqAdvanceConcurrentTest, SeqAdvanceConcurrentTest) { // Check if recovery preserves the last sequence number db_impl->FlushWAL(true); ReOpenNoDelete(); + assert(db != nullptr); db_impl = reinterpret_cast(db->GetRootDB()); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); @@ -1158,6 +1160,7 @@ TEST_P(SeqAdvanceConcurrentTest, SeqAdvanceConcurrentTest) { // Check if recovery after flush preserves the last sequence number db_impl->FlushWAL(true); ReOpenNoDelete(); + assert(db != nullptr); db_impl = reinterpret_cast(db->GetRootDB()); seq = db_impl->GetLatestSequenceNumber(); ASSERT_EQ(exp_seq, seq); @@ -1212,6 +1215,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecoveryTest) { wp_db->db_impl_->FlushWAL(true); wp_db->TEST_Crash(); ReOpenNoDelete(); + assert(db != nullptr); wp_db = dynamic_cast(db); // After recovery, all the uncommitted txns (0 and 1) should be inserted into // delayed_prepared_ @@ -1256,6 +1260,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecoveryTest) { wp_db->db_impl_->FlushWAL(true); wp_db->TEST_Crash(); ReOpenNoDelete(); + assert(db != nullptr); wp_db = dynamic_cast(db); ASSERT_TRUE(wp_db->prepared_txns_.empty()); ASSERT_FALSE(wp_db->delayed_prepared_empty_); @@ -1290,6 +1295,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecoveryTest) { delete txn2; wp_db->db_impl_->FlushWAL(true); ReOpenNoDelete(); + assert(db != nullptr); wp_db = dynamic_cast(db); ASSERT_TRUE(wp_db->prepared_txns_.empty()); ASSERT_TRUE(wp_db->delayed_prepared_empty_); @@ -1590,6 +1596,7 @@ TEST_P(WritePreparedTransactionTest, RollbackTest) { db_impl->FlushWAL(true); dynamic_cast(db)->TEST_Crash(); ReOpenNoDelete(); + assert(db != nullptr); wp_db = dynamic_cast(db); txn = db->GetTransactionByName("xid0"); ASSERT_FALSE(wp_db->delayed_prepared_empty_); diff --git a/utilities/transactions/write_unprepared_transaction_test.cc b/utilities/transactions/write_unprepared_transaction_test.cc index 8ec7f6bfb..009991bb7 100644 --- a/utilities/transactions/write_unprepared_transaction_test.cc +++ b/utilities/transactions/write_unprepared_transaction_test.cc @@ -250,7 +250,7 @@ TEST_P(WriteUnpreparedTransactionTest, RecoveryTest) { wup_db->db_impl_->FlushWAL(true); wup_db->TEST_Crash(); ReOpenNoDelete(); - wup_db = dynamic_cast(db); + assert(db != nullptr); db->GetAllPreparedTransactions(&prepared_trans); ASSERT_EQ(prepared_trans.size(), a == UNPREPARED ? 0 : 1);