From 500e508c6db2d8c138078661c4c6504269dd18d1 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 15 Aug 2013 16:26:17 +0100 Subject: [PATCH] fix up some coverity issues --- persistent-data/block.h | 1 - persistent-data/cache.h | 24 +++++++++++++++++++----- persistent-data/data-structures/btree.h | 8 ++++++-- persistent-data/hex_dump.cc | 5 ++++- thin-provisioning/metadata_dumper.cc | 1 + thin-provisioning/restore_emitter.cc | 1 + thin-provisioning/superblock.cc | 2 ++ thin-provisioning/thin_check.cc | 3 ++- thin-provisioning/thin_rmap.cc | 9 ++++++++- 9 files changed, 43 insertions(+), 11 deletions(-) diff --git a/persistent-data/block.h b/persistent-data/block.h index a39da3d..f7020d2 100644 --- a/persistent-data/block.h +++ b/persistent-data/block.h @@ -65,7 +65,6 @@ namespace persistent_data { int fd_; block_address nr_blocks_; mode mode_; - bool writeable_; }; template diff --git a/persistent-data/cache.h b/persistent-data/cache.h index b13e864..6c4e660 100644 --- a/persistent-data/cache.h +++ b/persistent-data/cache.h @@ -68,15 +68,29 @@ namespace base { v_(v) { } - struct { - value_entry *next_, *prev_; - } lru_; + struct lru { + lru() + : next_(0), + prev_(0) { + } + + value_entry *next_, *prev_; + }; + + struct lookup { + lookup() + : parent_(0), + left_(0), + right_(0), + color_() { + } - struct { value_entry *parent_, *left_, *right_; int color_; - } lookup_; + }; + lru lru_; + lookup lookup_; unsigned ref_count_; value_type v_; }; diff --git a/persistent-data/data-structures/btree.h b/persistent-data/data-structures/btree.h index 30a3577..26e687a 100644 --- a/persistent-data/data-structures/btree.h +++ b/persistent-data/data-structures/btree.h @@ -235,6 +235,7 @@ namespace persistent_data { public: typedef transaction_manager::read_ref read_ref; typedef transaction_manager::write_ref write_ref; + typedef boost::optional maybe_block; shadow_spine(transaction_manager::ptr tm, block_manager<>::validator::ptr v) @@ -282,14 +283,17 @@ namespace persistent_data { } block_address get_root() const { - return root_; + if (root_) + return *root_; + + throw std::runtime_error("shadow spine has no root"); } private: transaction_manager::ptr tm_; block_manager<>::validator::ptr validator_; std::list::write_ref> spine_; - block_address root_; + maybe_block root_; }; // Used to keep a record of a nested btree's position. diff --git a/persistent-data/hex_dump.cc b/persistent-data/hex_dump.cc index 353ed33..ec3380e 100644 --- a/persistent-data/hex_dump.cc +++ b/persistent-data/hex_dump.cc @@ -29,6 +29,8 @@ void base::hex_dump(ostream &out, void const *data_, size_t len) { unsigned char const *data = reinterpret_cast(data_), *end = data + len; + + ios_base::fmtflags old_flags = out.flags(); out << hex; while (data < end) { @@ -36,7 +38,8 @@ void base::hex_dump(ostream &out, void const *data_, size_t len) out << setw(2) << setfill('0') << (unsigned) *data << " "; out << endl; } - out << dec; + + out.setf(old_flags); } //---------------------------------------------------------------- diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index a611354..8ade304 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -40,6 +40,7 @@ namespace { md_sm_(md_sm), data_sm_(data_sm), in_range_(false), + time_(), found_errors_(false) { } diff --git a/thin-provisioning/restore_emitter.cc b/thin-provisioning/restore_emitter.cc index b1fe870..fd1d4ab 100644 --- a/thin-provisioning/restore_emitter.cc +++ b/thin-provisioning/restore_emitter.cc @@ -32,6 +32,7 @@ namespace { restorer(metadata::ptr md) : md_(md), in_superblock_(false), + nr_data_blocks_(), empty_mapping_(new_mapping_tree()) { } diff --git a/thin-provisioning/superblock.cc b/thin-provisioning/superblock.cc index 130e70d..b89ac64 100644 --- a/thin-provisioning/superblock.cc +++ b/thin-provisioning/superblock.cc @@ -37,6 +37,7 @@ superblock_traits::unpack(superblock_disk const &disk, superblock &value) value.metadata_nr_blocks_ = to_cpu(disk.metadata_nr_blocks_); value.compat_flags_ = to_cpu(disk.compat_flags_); + value.compat_ro_flags_ = to_cpu(disk.compat_ro_flags_); value.incompat_flags_ = to_cpu(disk.incompat_flags_); } @@ -70,6 +71,7 @@ superblock_traits::pack(superblock const &value, superblock_disk &disk) disk.metadata_nr_blocks_ = to_disk(value.metadata_nr_blocks_); disk.compat_flags_ = to_disk(value.compat_flags_); + disk.compat_ro_flags_ = to_disk(value.compat_ro_flags_); disk.incompat_flags_ = to_disk(value.incompat_flags_); } diff --git a/thin-provisioning/thin_check.cc b/thin-provisioning/thin_check.cc index e0ea2c1..b5826df 100644 --- a/thin-provisioning/thin_check.cc +++ b/thin-provisioning/thin_check.cc @@ -216,7 +216,8 @@ namespace { class mapping_reporter : public mapping_tree_detail::damage_visitor { public: mapping_reporter(nested_output &out) - : out_(out) { + : out_(out), + err_(NO_ERROR) { } virtual void visit(mapping_tree_detail::missing_devices const &d) { diff --git a/thin-provisioning/thin_rmap.cc b/thin-provisioning/thin_rmap.cc index f58682d..3b90c52 100644 --- a/thin-provisioning/thin_rmap.cc +++ b/thin-provisioning/thin_rmap.cc @@ -150,7 +150,14 @@ int main(int argc, char **argv) case 1: // region - regions.push_back(parse_region(optarg)); + try { + regions.push_back(parse_region(optarg)); + + } catch (std::exception const &e) { + cerr << e.what(); + return 1; + } + break; default: