From 5692d3421962a0654f19d5c070431c7313fe4c92 Mon Sep 17 00:00:00 2001 From: "James E. King III" Date: Mon, 13 Aug 2018 23:49:06 +0000 Subject: [PATCH] clean up some coverity-identified issues, mostly uninitialized class members --- example/line_wrapping_filter.hpp | 4 ++-- include/boost/iostreams/detail/adapter/direct_adapter.hpp | 1 + include/boost/iostreams/detail/buffer.hpp | 2 +- src/lzma.cpp | 2 +- src/zlib.cpp | 3 ++- test/detail/temp_file.hpp | 2 +- test/mapped_file_test.cpp | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/example/line_wrapping_filter.hpp b/example/line_wrapping_filter.hpp index fba32a694..f22610665 100644 --- a/example/line_wrapping_filter.hpp +++ b/example/line_wrapping_filter.hpp @@ -49,7 +49,7 @@ class line_wrapping_stdio_filter : public stdio_filter { class line_wrapping_input_filter : public input_filter { public: explicit line_wrapping_input_filter(int line_length = 80) - : line_length_(line_length), col_no_(0), has_next_(false) + : line_length_(line_length), col_no_(0), next_(0), has_next_(false) { } template @@ -91,7 +91,7 @@ class line_wrapping_input_filter : public input_filter { int line_length_; int col_no_; int next_; - int has_next_; + bool has_next_; }; class line_wrapping_output_filter : public output_filter { diff --git a/include/boost/iostreams/detail/adapter/direct_adapter.hpp b/include/boost/iostreams/detail/adapter/direct_adapter.hpp index 243b4b0ab..60fe8c274 100644 --- a/include/boost/iostreams/detail/adapter/direct_adapter.hpp +++ b/include/boost/iostreams/detail/adapter/direct_adapter.hpp @@ -58,6 +58,7 @@ class direct_adapter_base { explicit direct_adapter_base(const Direct& d); typedef is_convertible is_double; struct pointers { + pointers() : beg(0), ptr(0), end(0) { } char_type *beg, *ptr, *end; }; void init_input(mpl::true_); diff --git a/include/boost/iostreams/detail/buffer.hpp b/include/boost/iostreams/detail/buffer.hpp index 35cb33c70..59617f4eb 100644 --- a/include/boost/iostreams/detail/buffer.hpp +++ b/include/boost/iostreams/detail/buffer.hpp @@ -205,7 +205,7 @@ void basic_buffer::swap(basic_buffer& rhs) template buffer::buffer(std::streamsize buffer_size) - : basic_buffer(buffer_size) { } + : basic_buffer(buffer_size), ptr_(data()), eptr_(data() + buffer_size) { } template inline void buffer::set(std::streamsize ptr, std::streamsize end) diff --git a/src/lzma.cpp b/src/lzma.cpp index 5d7bb3cfb..8d41cca8c 100644 --- a/src/lzma.cpp +++ b/src/lzma.cpp @@ -75,7 +75,7 @@ void lzma_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(int error) namespace detail { lzma_base::lzma_base() - : stream_(new lzma_stream) + : stream_(new lzma_stream), level(lzma::default_compression) { } lzma_base::~lzma_base() { delete static_cast(stream_); } diff --git a/src/zlib.cpp b/src/zlib.cpp index 3dd7b1a89..66380689b 100644 --- a/src/zlib.cpp +++ b/src/zlib.cpp @@ -91,7 +91,8 @@ void zlib_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(int error) namespace detail { zlib_base::zlib_base() - : stream_(new z_stream), calculate_crc_(false), crc_(0), crc_imp_(0) + : stream_(new z_stream), calculate_crc_(false), crc_(0), crc_imp_(0), + total_in_(0), total_out_(0) { } zlib_base::~zlib_base() { delete static_cast(stream_); } diff --git a/test/detail/temp_file.hpp b/test/detail/temp_file.hpp index d8dbe1074..e8605d0db 100644 --- a/test/detail/temp_file.hpp +++ b/test/detail/temp_file.hpp @@ -34,7 +34,7 @@ class temp_file { // Constructs a temp file which does not initially exist. temp_file() { set_name(); } - ~temp_file() { std::remove(name_.c_str()); } + ~temp_file() { (void)std::remove(name_.c_str()); } const ::std::string name() const { return name_; } operator const ::std::string() const { return name_; } private: diff --git a/test/mapped_file_test.cpp b/test/mapped_file_test.cpp index 578451e89..29a85fd9a 100644 --- a/test/mapped_file_test.cpp +++ b/test/mapped_file_test.cpp @@ -289,7 +289,7 @@ void mapped_file_test() { boost::iostreams::test::test_file orig; char name[50]; - std::strcpy(name, orig.name().c_str()); + std::strncpy(name, orig.name().c_str(), 50); mapped_file mf((char*) name);