Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2005-06-08 04:21:41


Currently the gzip test fails on 64-bit system because of 32/64-bit issues
in 'iostreams/filter/gzip.hpp'. Attached patch fixes this, and additionally
renames the functions read_byte() to read_uint8() and read_long() to
read_uint32() as this is what they actually do.

The patch has been tested on a 32 bit system (Linux/GCC 3.4.2) and on a 64
bit system (Tru64/CXX 6.5-042, GCC 3.4.3). Ok to commit?

Markus

Index: filter/gzip.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/iostreams/filter/gzip.hpp,v
retrieving revision 1.14
diff -u -w -r1.14 gzip.hpp
--- filter/gzip.hpp 20 May 2005 04:11:11 -0000 1.14
+++ filter/gzip.hpp 8 Jun 2005 09:12:39 -0000
@@ -353,21 +353,21 @@
     static gzip_params make_params(int window_bits);
 
     template<typename Source>
- static int read_byte(Source& src, int error)
+ static uint8_t read_uint8(Source& src, int error)
     {
         int c;
         if ((c = boost::iostreams::get(src)) == EOF || c == WOULD_BLOCK)
             throw gzip_error(error);
- return static_cast<unsigned char>(traits_type::to_char_type(c));
+ return static_cast<uint8_t>(traits_type::to_char_type(c));
     }
 
     template<typename Source>
- static long read_long(Source& src, int error)
+ static uint32_t read_uint32(Source& src, int error)
     {
- int b1 = read_byte(src, error);
- int b2 = read_byte(src, error);
- int b3 = read_byte(src, error);
- int b4 = read_byte(src, error);
+ uint8_t b1 = read_uint8(src, error);
+ uint8_t b2 = read_uint8(src, error);
+ uint8_t b3 = read_uint8(src, error);
+ uint8_t b4 = read_uint8(src, error);
         return b1 + (b2 << 8) + (b3 << 16) + (b4 << 24);
     }
 
@@ -412,16 +412,17 @@
         {
             throw gzip_error(gzip::bad_header);
         }
- mtime_ = read_long(src, gzip::bad_header); // MTIME.
- read_byte(src, gzip::bad_header); // XFL.
- os_ = read_byte(src, gzip::bad_header); // OS.
+ mtime_ = read_uint32(src, gzip::bad_header); // MTIME.
+ read_uint8(src, gzip::bad_header); // XFL.
+ os_ = read_uint8(src, gzip::bad_header); // OS.
         if (flags & boost::iostreams::gzip::flags::text)
             flags_ |= f_text;
 
         // Skip extra field. (From J. Halleaux; see note at top.)
         if (flags & gzip::flags::extra) {
- int length = read_byte(src, gzip::bad_header) +
- (read_byte(src, gzip::bad_header) << 8);
+ int length = static_cast<int>(
+ read_uint8(src, gzip::bad_header) +
+ (read_uint8(src, gzip::bad_header) << 8));
             // length is garbage if EOF but the loop below will quit anyway.
             do { }
             while (length-- != 0 && !is_eof(boost::iostreams::get(src)));
@@ -432,8 +433,8 @@
         if (flags & gzip::flags::comment) // Read comment.
             comment_ = read_string(src);
         if (flags & gzip::flags::header_crc) { // Skip header crc.
- read_byte(src, gzip::bad_header);
- read_byte(src, gzip::bad_header);
+ read_uint8(src, gzip::bad_header);
+ read_uint8(src, gzip::bad_header);
         }
     }
 
@@ -447,13 +448,11 @@
             footer += c;
         detail::range_adapter<input, std::string>
             rng(footer.begin(), footer.end());
- if ( static_cast<unsigned long>(read_long(rng, gzip::bad_footer))
- !=
- this->crc() )
+ if ( read_uint32(rng, gzip::bad_footer) != this->crc() )
         {
             throw gzip_error(gzip::bad_crc);
         }
- if (read_long(rng, gzip::bad_footer) != this->total_out())
+ if (static_cast<int>(read_uint32(rng, gzip::bad_footer)) != this->total_out())
             throw gzip_error(gzip::bad_length);
     }
     enum {


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk