From 5d0b98fb46b1aba137677d45b3c74726143eb6fa Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Tue, 15 Sep 2015 14:25:23 +0200 Subject: Copying and moving is implicitly disabled anyway --- include/io/izlibstream.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/io/izlibstream.h b/include/io/izlibstream.h index edf632eddf..4e9dc9c1ee 100644 --- a/include/io/izlibstream.h +++ b/include/io/izlibstream.h @@ -47,10 +47,6 @@ public: explicit inflate_streambuf(std::istream& input, size_t bufsize = 32768, int window_bits = 32 + 15); ~inflate_streambuf() noexcept; - //No copying or moving - inflate_streambuf(const inflate_streambuf&) = delete; - inflate_streambuf& operator=(const inflate_streambuf&) = delete; - ///@return the wrapped istream std::istream& get_istr() const { return is; } -- cgit 0.0.5-2-1-g0f52 From 2d8cc72760cfd26e56b70786b30c4f6dafe04aa0 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Tue, 15 Sep 2015 14:59:02 +0200 Subject: Handle nullptr message in zlib_error --- include/io/zlib_error.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/io/zlib_error.h b/include/io/zlib_error.h index ce375a6ccd..1ecb50e553 100644 --- a/include/io/zlib_error.h +++ b/include/io/zlib_error.h @@ -11,7 +11,9 @@ public: const int errcode; explicit zlib_error(const char* msg, int errcode): - std::runtime_error(std::string(zError(errcode)) + ": " + msg), + std::runtime_error(msg + ? std::string(zError(errcode)) + ": " + msg + : zError(errcode)), errcode(errcode) {} }; -- cgit 0.0.5-2-1-g0f52 From ef10a4f34a3f10bc1fc7ee0b7b1be6f37d286741 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Tue, 15 Sep 2015 20:41:11 +0200 Subject: Add test for inflating zlib data --- test/testfiles/bigtest.zlib | Bin 0 -> 528 bytes test/zlibstream_test.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/testfiles/bigtest.zlib diff --git a/test/testfiles/bigtest.zlib b/test/testfiles/bigtest.zlib new file mode 100644 index 0000000000..36aeee57fb Binary files /dev/null and b/test/testfiles/bigtest.zlib differ diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h index f37dcdbd91..d2e6b6ee82 100644 --- a/test/zlibstream_test.h +++ b/test/zlibstream_test.h @@ -89,6 +89,22 @@ public: } } + void test_inflate_zlib() + { + std::ifstream zlib_in("bigtest.zlib", std::ios::binary); + TS_ASSERT(zlib_in); + + std::stringbuf data; + izlibstream izls(zlib_in, 256); + izls.exceptions(std::ios::failbit); + TS_ASSERT(izls.good()); + + TS_ASSERT_THROWS_NOTHING(izls >> &data); + TS_ASSERT(izls); + TS_ASSERT(izls.eof()); + TS_ASSERT_EQUALS(data.str(), bigtest.str()); + } + void test_inflate_corrupt() { std::ifstream gzip_in("bigtest_corrupt.nbt", std::ios::binary); -- cgit 0.0.5-2-1-g0f52 From 93a4f406d0b827026d26703c4623b1b846f65ca4 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Tue, 15 Sep 2015 23:37:49 +0200 Subject: Fix base constructor calls of i/ostream Add missing noexcept --- include/io/izlibstream.h | 6 ++---- include/io/ozlibstream.h | 6 ++---- src/io/izlibstream.cpp | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/io/izlibstream.h b/include/io/izlibstream.h index 4e9dc9c1ee..6d58d56b86 100644 --- a/include/io/izlibstream.h +++ b/include/io/izlibstream.h @@ -76,10 +76,8 @@ public: * @param bufsize the size of the internal buffers */ explicit izlibstream(std::istream& input, size_t bufsize = 32768): - buf(input, bufsize) - { - init(&buf); - } + std::istream(&buf), buf(input, bufsize) + {} ///@return the wrapped istream std::istream& get_istr() const { return buf.get_istr(); } diff --git a/include/io/ozlibstream.h b/include/io/ozlibstream.h index 6ebd3c0dd0..954bcc182d 100644 --- a/include/io/ozlibstream.h +++ b/include/io/ozlibstream.h @@ -85,10 +85,8 @@ public: * Refer to the zlib documentation of deflateInit2 for a detailed explanation of the arguments. */ explicit ozlibstream(std::ostream& output, int level = -1, int window_bits = 15, int mem_level = 8, int strategy = Z_DEFAULT_STRATEGY): - buf(output, level, window_bits, mem_level, strategy) - { - init(&buf); - } + std::ostream(&buf), buf(output, level, window_bits, mem_level, strategy) + {} ///@return the wrapped ostream std::ostream& get_ostr() const { return buf.get_ostr(); } diff --git a/src/io/izlibstream.cpp b/src/io/izlibstream.cpp index db69e0e626..6b7a75189a 100644 --- a/src/io/izlibstream.cpp +++ b/src/io/izlibstream.cpp @@ -39,7 +39,7 @@ inflate_streambuf::inflate_streambuf(std::istream& input, size_t bufsize, int wi setg(end, end, end); } -inflate_streambuf::~inflate_streambuf() +inflate_streambuf::~inflate_streambuf() noexcept { inflateEnd(&zstr); } -- cgit 0.0.5-2-1-g0f52 From edaaac5a6c7d20eb5baa6de27aa79cb50878a10b Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Tue, 15 Sep 2015 23:40:49 +0200 Subject: Moving and copying is disabled for ozlibstream too --- include/io/ozlibstream.h | 9 --------- test/zlibstream_test.h | 1 + 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/include/io/ozlibstream.h b/include/io/ozlibstream.h index 954bcc182d..0e19aaaa2b 100644 --- a/include/io/ozlibstream.h +++ b/include/io/ozlibstream.h @@ -20,7 +20,6 @@ #ifndef OZLIBSTREAM_H_INCLUDED #define OZLIBSTREAM_H_INCLUDED -#include "io/zlib_error.h" #include #include #include @@ -38,14 +37,6 @@ public: explicit deflate_streambuf(std::ostream& output, int level = -1, int window_bits = 15, int mem_level = 8, int strategy = Z_DEFAULT_STRATEGY); ~deflate_streambuf() noexcept; - //Moving - deflate_streambuf(deflate_streambuf&&) noexcept = default; - deflate_streambuf& operator=(deflate_streambuf&&) noexcept = default; - - //No copying - deflate_streambuf(const deflate_streambuf&) = delete; - deflate_streambuf& operator=(const deflate_streambuf&) = delete; - std::ostream& get_ostr() const { return os; } private: diff --git a/test/zlibstream_test.h b/test/zlibstream_test.h index d2e6b6ee82..8e9ca6b0f2 100644 --- a/test/zlibstream_test.h +++ b/test/zlibstream_test.h @@ -20,6 +20,7 @@ #include #include "io/izlibstream.h" #include "io/ozlibstream.h" +#include "io/zlib_error.h" #include #include -- cgit 0.0.5-2-1-g0f52