rocksdb: Fixed 'Dead assignment' and 'Dead initialization' scan-build warnings

Summary:
This diff contains trivial fixes for 6 scan-build warnings:

**db/c_test.c**
`db` variable is never read. Removed assignment.
scan-build report:
http://home.fburl.com/~sugak/latest20/report-9b77d2.html#EndPath

**db/db_iter.cc**
`skipping` local variable is assigned to false. Then in the next switch block the only "non return" case assign `skipping` to true, the rest cases don't use it and all do return.
scan-build report:
http://home.fburl.com/~sugak/latest20/report-13fca7.html#EndPath

**db/log_reader.cc**
In `bool Reader::SkipToInitialBlock()` `offset_in_block` local variable is assigned to 0 `if (offset_in_block > kBlockSize - 6)` and then never used. Removed the assignment and renamed it to `initial_offset_in_block` to avoid confusion.
scan-build report:
http://home.fburl.com/~sugak/latest20/report-a618dd.html#EndPath

In `bool Reader::ReadRecord(Slice* record, std::string* scratch)` local variable `in_fragmented_record` in switch case `kFullType` block is assigned to false and then does `return` without use. In the other switch case `kFirstType` block the same `in_fragmented_record` is assigned to false, but later assigned to true without prior use. Removed assignment for both cases.
scan-build reprots:
http://home.fburl.com/~sugak/latest20/report-bb86b0.html#EndPath
http://home.fburl.com/~sugak/latest20/report-a975be.html#EndPath

**table/plain_table_key_coding.cc**
Local variable `user_key_size` is assigned when declared. But then in both places where it is used assigned to `static_cast<uint32_t>(key.size() - 8)`. Changed to initialize the variable to the proper value in declaration.
scan-build report:
http://home.fburl.com/~sugak/latest20/report-9e6b86.html#EndPath

**tools/db_stress.cc**
Missing `break` in switch case block. This seems to be a bug. Added missing `break`.

Test Plan:
Make sure all tests are passing and scan-build does not report 'Dead assignment' and 'Dead initialization' bugs.
```lang=bash
% make check
% make analyze
```

Reviewers: meyering, igor, kradhakrishnan, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D33795
main
Igor Sugak 10 years ago
parent 5636c4a80b
commit 62f7a1be4f
  1. 2
      db/c_test.c
  2. 1
      db/db_iter.cc
  3. 23
      db/log_reader.cc
  4. 5
      table/plain_table_key_coding.cc
  5. 1
      tools/db_stress.cc

@ -388,7 +388,7 @@ int main(int argc, char** argv) {
Free(&err);
StartPhase("open_error");
db = rocksdb_open(options, dbname, &err);
rocksdb_open(options, dbname, &err);
CheckCondition(err != NULL);
Free(&err);

@ -225,7 +225,6 @@ void DBIter::FindNextUserEntryInternal(bool skipping) {
num_skipped++; // skip this entry
PERF_COUNTER_ADD(internal_key_skipped_count, 1);
} else {
skipping = false;
switch (ikey.type) {
case kTypeDeletion:
// Arrange to skip all upcoming entries for this key since

@ -39,12 +39,11 @@ Reader::~Reader() {
}
bool Reader::SkipToInitialBlock() {
size_t offset_in_block = initial_offset_ % kBlockSize;
uint64_t block_start_location = initial_offset_ - offset_in_block;
size_t initial_offset_in_block = initial_offset_ % kBlockSize;
uint64_t block_start_location = initial_offset_ - initial_offset_in_block;
// Don't search a block if we'd be in the trailer
if (offset_in_block > kBlockSize - 6) {
offset_in_block = 0;
if (initial_offset_in_block > kBlockSize - 6) {
block_start_location += kBlockSize;
}
@ -82,16 +81,12 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) {
const unsigned int record_type = ReadPhysicalRecord(&fragment);
switch (record_type) {
case kFullType:
if (in_fragmented_record) {
if (in_fragmented_record && !scratch->empty()) {
// Handle bug in earlier versions of log::Writer where
// it could emit an empty kFirstType record at the tail end
// of a block followed by a kFullType or kFirstType record
// at the beginning of the next block.
if (scratch->empty()) {
in_fragmented_record = false;
} else {
ReportCorruption(scratch->size(), "partial record without end(1)");
}
ReportCorruption(scratch->size(), "partial record without end(1)");
}
prospective_record_offset = physical_record_offset;
scratch->clear();
@ -100,16 +95,12 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) {
return true;
case kFirstType:
if (in_fragmented_record) {
if (in_fragmented_record && !scratch->empty()) {
// Handle bug in earlier versions of log::Writer where
// it could emit an empty kFirstType record at the tail end
// of a block followed by a kFullType or kFirstType record
// at the beginning of the next block.
if (scratch->empty()) {
in_fragmented_record = false;
} else {
ReportCorruption(scratch->size(), "partial record without end(2)");
}
ReportCorruption(scratch->size(), "partial record without end(2)");
}
prospective_record_offset = physical_record_offset;
scratch->assign(fragment.data(), fragment.size());

@ -73,10 +73,9 @@ Status PlainTableKeyEncoder::AppendKey(const Slice& key, WritableFile* file,
Slice key_to_write = key; // Portion of internal key to write out.
uint32_t user_key_size = fixed_user_key_len_;
uint32_t user_key_size = static_cast<uint32_t>(key.size() - 8);
if (encoding_type_ == kPlain) {
if (fixed_user_key_len_ == kPlainTableVariableLength) {
user_key_size = static_cast<uint32_t>(key.size() - 8);
// Write key length
char key_size_buf[5]; // tmp buffer for key size as varint32
char* ptr = EncodeVarint32(key_size_buf, user_key_size);
@ -93,8 +92,6 @@ Status PlainTableKeyEncoder::AppendKey(const Slice& key, WritableFile* file,
char size_bytes[12];
size_t size_bytes_pos = 0;
user_key_size = static_cast<uint32_t>(key.size() - 8);
Slice prefix =
prefix_extractor_->Transform(Slice(key.data(), user_key_size));
if (key_count_for_prefix_ == 0 || prefix != pre_prefix_.GetKey() ||

@ -1726,6 +1726,7 @@ class StressTest {
break;
case rocksdb::kLZ4Compression:
compression = "lz4";
break;
case rocksdb::kLZ4HCCompression:
compression = "lz4hc";
break;

Loading…
Cancel
Save