Boost C++ Libraries: Ticket #8203: filtering_ostream fails to write 0xFF characters with XCode https://svn.boost.org/trac10/ticket/8203 <p> 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. </p> <p> I managed to reduce the code required to reproduce it down to: </p> <p> <em> filtering stream fails to write 0xFF chars to ostream. Have </em> reproduced with ofstream too std::ostringstream ostm(std::ios_base::out | std::ios_base::binary); </p> <p> <em> Use empty filtering stream. Problem was originally found with </em>zlib_compressor boost::iostreams::filtering_ostream filterStream; filterStream.push( ostm ); </p> <p> const unsigned fileSize = 30000; </p> <p> for( unsigned nWritten = 0; nWritten &lt; fileSize; ++nWritten) { </p> <blockquote> <p> const char eofTest = -1; <em> Only fails with 0xFF character any other value fine </em></p> </blockquote> <blockquote> <p> filterStream.write( &amp;eofTest, sizeof eofTest); </p> </blockquote> <p> } filterStream.flush(); </p> <p> <em> This assert fails with Xcode 4.6 assert( ostm.str().size() == fileSize); </em></p> <p> 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. </p> <p> 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: </p> <p> static std::streamsize write(T&amp; t, const typename char_type_of&lt;T&gt;::type* s, std::streamsize n) { </p> <blockquote> <p> return t.rdbuf()-&gt;sputn(s, n); </p> </blockquote> <p> } </p> <p> to: </p> <p> static std::streamsize write(T&amp; t, const typename char_type_of&lt;T&gt;::type* s, std::streamsize n) { </p> <blockquote> <p> t.write(s, n); return n; </p> </blockquote> <p> } </p> <p> It looks like bypassing the ofstream in Xcode and going to the lower level rdbuf::sputn causes the issue. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8203 Trac 1.4.3 anonymous Thu, 28 Feb 2013 12:33:21 GMT attachment set https://svn.boost.org/trac10/ticket/8203 https://svn.boost.org/trac10/ticket/8203 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">iostream_filter_issue.cpp</span> </li> </ul> <p> Demonstrates issue writing 0xFF through filtering_ostream on XCode </p> Ticket support@… Thu, 28 Feb 2013 15:56:19 GMT <link>https://svn.boost.org/trac10/ticket/8203#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8203#comment:1</guid> <description> <p> I also had to change the use of sputn in write_device_impl::write by using sputc instead that doesn't seem to have a problem: </p> <p> static std::streamsize write </p> <blockquote> <p> (T&amp; t, const typename char_type_of&lt;T&gt;::type* s, std::streamsize n) </p> </blockquote> <p> { </p> <blockquote> <p> typedef typename char_type_of&lt;T&gt;::type char_type; typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type; const char_type* pNext = s; while( pNext &lt; s + n ) { </p> <blockquote> <p> if ( traits_type::eq_int_type( t.sputc(*pNext), traits_type::eof() ) ) { </p> <blockquote> <p> break; </p> </blockquote> <p> } ++pNext; </p> </blockquote> <p> } return pNext - s; </p> </blockquote> <p> } </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 21 Sep 2013 05:01:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8203#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8203#comment:2</guid> <description> <p> I'm pretty sure this is a duplicate of <a class="new ticket" href="https://svn.boost.org/trac10/ticket/8150" title="#8150: Bugs: gzip_compressor produces corrupt data when used with filtering_ostream (new)">#8150</a>: </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/8203"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/8203</a> </p> <p> The fix is to update libc++. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 23 Sep 2013 09:00:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8203#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8203#comment:3</guid> <description> <p> Thanks. That looks like it. The streambuf header in Xcode 4.6 was updated in January 2013 and includes the fix. </p> <p> Please close the bug. </p> </description> <category>Ticket</category> </item> </channel> </rss>