[Boost-bugs] [Boost C++ Libraries] #8203: filtering_ostream fails to write 0xFF characters with XCode

Subject: [Boost-bugs] [Boost C++ Libraries] #8203: filtering_ostream fails to write 0xFF characters with XCode
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-28 12:30:06


#8203: filtering_ostream fails to write 0xFF characters with XCode
-----------------------------------------------------+----------------------
 Reporter: support@… | Owner: turkanis
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: iostreams
  Version: Boost 1.51.0 | Severity: Problem
 Keywords: eof rdbuf filtering_ostream write xcode |
-----------------------------------------------------+----------------------
 I originally found the problem using the zlib_compressor to write to an
 ofstream. It worked correctly on Windows but in Xcode 4.6 occasionally a
 0xFF character was not written to the stream.

 I managed to reduce the code required to reproduce it down to:

 // filtering stream fails to write 0xFF chars to ostream. Have
 // reproduced with ofstream too
 std::ostringstream ostm(std::ios_base::out | std::ios_base::binary);

 // Use empty filtering stream. Problem was originally found with
 //zlib_compressor
 boost::iostreams::filtering_ostream filterStream;
 filterStream.push( ostm );

 const unsigned fileSize = 30000;

 for( unsigned nWritten = 0; nWritten < fileSize; ++nWritten)
 {
   const char eofTest = -1; // Only fails with 0xFF character any other
 value fine

   filterStream.write( &eofTest, sizeof eofTest);
 }
 filterStream.flush();

 // This assert fails with Xcode 4.6
 assert( ostm.str().size() == fileSize);

 The number of missing characters is equal to the number of times overflow
 gets called. I suspect it's something to do with EOF character detection
 as the problem doesn't happen with other character values.

 I was unable to find the exact reason for the problem but was able to get
 it work by changing this code in write.hpp:

 static std::streamsize write(T& t, const typename char_type_of<T>::type*
 s, std::streamsize n)
 {
   return t.rdbuf()->sputn(s, n);
 }

 to:

 static std::streamsize write(T& t, const typename char_type_of<T>::type*
 s, std::streamsize n)
 {
   t.write(s, n);
   return n;
 }

 It looks like bypassing the ofstream in Xcode and going to the lower level
 rdbuf::sputn causes the issue.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8203>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC