Boost logo

Boost :

From: Stefan van den Oord (stefan.vandenoord_at_[hidden])
Date: 2006-06-23 08:42:31


According to the boost web site, this mailing list is the preferred
way to report bugs, so I subscribed and send you this:

I believe the example
/boost/libs/serialization/example/portable_binary_oarchive.hpp doesn't
work correctly. On my platform, Mac OS X, the endian conversion is
performed. For a small negative number (say -42l), the endian
conversion results in a big negative number (-687865857). The size,
however, is computed _before_ the endian conversion, so it is 1 (one)
in this case, which is not high enough to hold the converted long.

I guess the solution is to do the endian conversion first, then the
size computation. That seems to work for me. Based on the 1_33_1
sources, my version of save_impl is now:

    void save_impl(long l){
        // we choose to use litle endian
        #ifdef BOOST_BIG_ENDIAN
            char * first = static_cast<char *>(static_cast<void *>(& l));
            char * last = first + sizeof(l) - 1;
            for(;first < last;++first, --last)
                char x = *last;
                *last = *first;
                *first = x;
                long ll = l;
                char size = 0;
                        ll >>= 8;
                }while(ll != -1 && ll != 0);

                save_binary(& l, size);

I hope this helps in improving the example.


Stefan van den Oord

Boost list run by bdawes at, gregod at, cpdaniel at, john at