Opened 12 years ago

Closed 12 years ago

Last modified 9 years ago

#4906 closed Bugs (wontfix)

Portable Binary Archive fails for -1 on AIX

Reported by: Avi Singh Bahra <avibahra@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.45.0 Severity: Showstopper
Keywords: Portable Binary Archive Cc:

Description

================ Main.cpp ========================= This example demonstrates a bug in portable binary format on AIX when serialising -1 that is specific only to the AIX compiler/platform (i.e HPUX/Acc and linux/gcc run without any problems) However on AIX on the restore, an exception is thrown in load_impl(..) This test consists of 1 files 1/ Main.cpp It appears that when restoring an integer of value -1, it binds to: void load(T & t){ boost::intmax_t l; load_impl(l, sizeof(T)); use cast to avoid compile time warning t = static_cast< T >(l); t = T(l); } void load_impl(boost::intmax_t & l, char maxsize); This appears to be the wrong load as the signature of load_impl() will lead to truncation ! 2/ Note You will need to pull out and compile the portable binary archive from the boost serialisation example dir.

#include <sstream> #include <ostream> #include <iostream> #include <fstream> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include "portable_binary_oarchive.hpp" #include "portable_binary_iarchive.hpp" #include <boost/serialization/serialization.hpp>

using namespace std;

void save(const std::string& fileName, const int& ts, bool textArchive)

{

if ( textArchive ) std::cout << "Text archive Saving " << ts ; else std::cout << "portable binary archive Saving " << ts; try {

if (textArchive) {

std::ofstream ofs( "fred.txt" ); boost::archive::text_oarchive ar( ofs ); ar << ts;

} else {

std::ofstream ofs( fileName.c_str(), ios::binary );

portable_binary_oarchive ar(ofs);

ar << ts;

}

std::cout << " OK \n";

} catch (const boost::archive::archive_exception& ae) {

std::cout << " save " << fileName << " failed. boost::archive exception "

<< ": " << ae.what() << std::endl;

}

}

void restore(const std::string& fileName, int& restored, bool textArchive) {

if ( textArchive ) std::cout << "Text archive Restoring "; else std::cout << "portable binary archive Restoring " ;

try {

if ( textArchive ) {

std::ifstream ifs( fileName.c_str() ); boost::archive::text_iarchive ar( ifs ); ar >> restored;

} else {

std::ifstream ifs( fileName.c_str(), ios::binary ); portable_binary_iarchive ar( ifs ); ar >> restored;

}

std::cout << restored << " OK \n";

} catch ( const boost::archive::archive_exception& ae ) {

std::cout << " restore " << fileName << " failed. boost::archive exception "

<< ": " << ae.what() << std::endl;

}

}

int main() {

{

int saved = -1; save("fred.txt",saved,true);

int restored = 44; restore("fred.txt",restored,true); assert(saved == restored);

} {

int saved = -1; save("fred.txt",saved,false); int restored = 44; restore("fred.txt",restored,false); assert(saved == restored);

} return 0;

}

Change History (3)

comment:1 by Robert Ramey, 12 years ago

Resolution: wontfix
Status: newclosed

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.

Robert Ramey

comment:2 by Vicente Botet <vicente.botet@…>, 12 years ago

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.

comment:3 by clord@…, 9 years ago

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.

see: http://stackoverflow.com/questions/2054939/char-is-signed-or-unsigned-by-default

Note: See TracTickets for help on using tickets.