Devious Fish
gzstream patch

gzstream patch

Applicability

This applies to the header-and-library version of the gzstream library.

This does not apply to the header-only version, which is fine.

Bug report

I’ve identified a bug in gzstream. It appeared on OS X 10.9 with the clang compiler (clang–600.0.57) and LLVM 3.5svn. Although I suspect it is at least partially cross-platform, I don’t know how broadly it is is exhibited.

When opening a file, construct-then-open works:

igzstream foobar;
foobar.open (“some_file”);
if (foobar.good()) { ...read the file... }

But the construct-to-open does not:

igzstream foobar (“some_file”);
if (foobar.good()) { ...read the file... }

Both pass ‘make test’, however, in the latter case, good() returns true but upon reading from the stream, nothing comes out. The unit test only checks if open succeeds; it does not validate data read.

Dx

The constructors for igzstream and ogzstream pass the file open parameters to gzstreambase during base class initialization when exhibiting the problem. Removing this and adding an open() within the constructor body (after base class initialization) fixes it.

The patch follows:

--- gzstream.h.orig 2015-10-30 15:57:24.000000000 -0400
+++ gzstream.h  2015-10-30 16:00:35.000000000 -0400
@@ -93,7 +93,9 @@
 public:
     igzstream() : std::istream( &buf) {} 
     igzstream( const char* name, int open_mode = std::ios::in)
-        : gzstreambase( name, open_mode), std::istream( &buf) {}  
+        : std::istream( &buf) {
+   gzstreambase::open (name, open_mode);
+    };
     gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
     void open( const char* name, int open_mode = std::ios::in) {
         gzstreambase::open( name, open_mode);
@@ -104,7 +106,9 @@
 public:
     ogzstream() : std::ostream( &buf) {}
     ogzstream( const char* name, int mode = std::ios::out)
-        : gzstreambase( name, mode), std::ostream( &buf) {}  
+        : std::ostream( &buf) {
+   gzstreambase::open (name, mode);
+    };
     gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
     void open( const char* name, int open_mode = std::ios::out) {
         gzstreambase::open( name, open_mode);