Boost C++ Libraries: Ticket #4906: Portable Binary Archive fails for -1 on AIX https://svn.boost.org/trac10/ticket/4906 <p> <em>================ Main.cpp ========================= </em> This example demonstrates a bug in portable binary format <em> on AIX when serialising -1 </em> that is specific only to the AIX compiler/platform <em> (i.e HPUX/Acc and linux/gcc run without any problems) </em> However on AIX on the restore, an exception is thrown <em> in load_impl(..) </em> <em> This test consists of 1 files </em> 1/ Main.cpp <em> </em> It appears that when restoring an integer of value -1, it binds to: <em> </em> void load(T &amp; t){ <em> boost::intmax_t l; </em> load_impl(l, sizeof(T)); <em> </em> use cast to avoid compile time warning <em> </em>t = static_cast&lt; T &gt;(l); <em> t = T(l); </em> } <em> </em> void load_impl(boost::intmax_t &amp; l, char maxsize); <em> </em> This appears to be the wrong load as the signature of load_impl() <em> will lead to truncation ! </em> <em>2/ Note You will need to pull out and compile the portable </em> binary archive from the boost serialisation example dir. </p> <p> #include &lt;sstream&gt; #include &lt;ostream&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;boost/archive/binary_oarchive.hpp&gt; #include &lt;boost/archive/binary_iarchive.hpp&gt; #include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/archive/text_oarchive.hpp&gt; #include "portable_binary_oarchive.hpp" #include "portable_binary_iarchive.hpp" #include &lt;boost/serialization/serialization.hpp&gt; </p> <p> using namespace std; </p> <blockquote> <p> void save(const std::string&amp; fileName, const int&amp; ts, bool textArchive) </p> </blockquote> <p> { </p> <blockquote> <p> if ( textArchive ) std::cout &lt;&lt; "Text archive Saving " &lt;&lt; ts ; else std::cout &lt;&lt; "portable binary archive Saving " &lt;&lt; ts; try { </p> <blockquote> <p> if (textArchive) { </p> <blockquote> <p> std::ofstream ofs( "fred.txt" ); boost::archive::text_oarchive ar( ofs ); ar &lt;&lt; ts; </p> </blockquote> <p> } else { </p> <blockquote> <p> std::ofstream ofs( fileName.c_str(), ios::binary ); </p> <blockquote> <p> portable_binary_oarchive ar(ofs); </p> </blockquote> <p> ar &lt;&lt; ts; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; " OK \n"; </p> </blockquote> <p> } catch (const boost::archive::archive_exception&amp; ae) { </p> <blockquote> <p> std::cout &lt;&lt; " save " &lt;&lt; fileName &lt;&lt; " failed. boost::archive exception " </p> <blockquote> <p> &lt;&lt; ": " &lt;&lt; ae.what() &lt;&lt; std::endl; </p> </blockquote> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> void restore(const std::string&amp; fileName, int&amp; restored, bool textArchive) { </p> <blockquote> <p> if ( textArchive ) std::cout &lt;&lt; "Text archive Restoring "; else std::cout &lt;&lt; "portable binary archive Restoring " ; </p> </blockquote> <blockquote> <p> try { </p> <blockquote> <p> if ( textArchive ) { </p> <blockquote> <p> std::ifstream ifs( fileName.c_str() ); boost::archive::text_iarchive ar( ifs ); ar &gt;&gt; restored; </p> </blockquote> <p> } else { </p> <blockquote> <p> std::ifstream ifs( fileName.c_str(), ios::binary ); portable_binary_iarchive ar( ifs ); ar &gt;&gt; restored; </p> </blockquote> <p> } </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; restored &lt;&lt; " OK \n"; </p> </blockquote> <p> } catch ( const boost::archive::archive_exception&amp; ae ) { </p> <blockquote> <p> std::cout &lt;&lt; " restore " &lt;&lt; fileName &lt;&lt; " failed. boost::archive exception " </p> <blockquote> <p> &lt;&lt; ": " &lt;&lt; ae.what() &lt;&lt; std::endl; </p> </blockquote> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> int main() { </p> <blockquote> <p> { </p> <blockquote> <p> int saved = -1; save("fred.txt",saved,true); </p> </blockquote> </blockquote> <blockquote> <blockquote> <p> int restored = 44; restore("fred.txt",restored,true); assert(saved == restored); </p> </blockquote> <p> } { </p> <blockquote> <p> int saved = -1; save("fred.txt",saved,false); int restored = 44; restore("fred.txt",restored,false); assert(saved == restored); </p> </blockquote> <p> } return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4906 Trac 1.4.3 Robert Ramey Mon, 06 Dec 2010 19:46:20 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4906#comment:1 https://svn.boost.org/trac10/ticket/4906#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> OK - looks like a compiler bug. I don't have this compiler. If you want to suggest a compiler specific workaround in the form of a patch, I would be willing to incorporate it. But lacking that there is not much I can do. You might want to contact the compiler vendor about this. </p> <p> Robert Ramey </p> Ticket Vicente Botet <vicente.botet@…> Fri, 10 Dec 2010 18:29:50 GMT <link>https://svn.boost.org/trac10/ticket/4906#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4906#comment:2</guid> <description> <p> As you have access to the compiler, maybe be you can run regression test on this compiler regularly, so we can take care of this and other bugs. </p> </description> <category>Ticket</category> </item> <item> <author>clord@…</author> <pubDate>Fri, 17 May 2013 17:43:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4906#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4906#comment:3</guid> <description> <p> It's not a compiler bug. The bug is in the example code (load_impl and save_impl in portable_binary_iarchive.hpp and portable_binary_oarchive.hpp respectively). The example code should not assume that 'char' is signed -- not all compilers implement char as default-signed. I suggest changing the above functions to use 'signed char' if you're trying to represent negative char in a portable manner. </p> <p> see: <a class="ext-link" href="http://stackoverflow.com/questions/2054939/char-is-signed-or-unsigned-by-default"><span class="icon">​</span>http://stackoverflow.com/questions/2054939/char-is-signed-or-unsigned-by-default</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>