Opened 10 years ago

Closed 10 years ago

#7498 closed Bugs (invalid)

archive::binary_iarchive failure loading map<string,string>

Reported by: kaedenn@… Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.51.0 Severity: Problem
Keywords: binary serialize map string Cc:

Description

I create two std::map<std::string, std::string> instances, one of which having two dozen contents, the other default-initialized. I serialize the former using boost::archive::binary_oarchive and load it into the latter using boost::archive::binary_iarchive.

// This Win32-specific test creates a std::map from strings to strings and
// then serializes it to a file. We then attempt to desearialize from that
// file. On boost_1_45_0 and boost_1_51_0 for Win32 this testcase fails on
// our company's secondary build machine.
/*
At the top of the call stack (see attachment for context),
    std::streamsize s = static_cast<std::streamsize>(count / sizeof(Elem));
    std::streamsize scount = m_sb.sgetn(
        static_cast<Elem *>(address), 
        s
    );
    if(scount != s)
        boost::serialization::throw_exception(
            archive_exception(archive_exception::input_stream_error)
        );
`scount` is 0, `s` is 8. It's trying to load a size_type, presumably for a string length or a map length.
*/

Attachments (1)

test_binary_archive_with_map.cpp (23.8 KB ) - added by anonymous 10 years ago.

Download all attachments as: .zip

Change History (4)

by anonymous, 10 years ago

comment:1 by kaedenn@…, 10 years ago

Severity: ShowstopperProblem

comment:2 by anonymous, 10 years ago

Opening the streams with std::ios::binary fixes the problem.

comment:3 by Robert Ramey, 10 years ago

Resolution: invalid
Status: newclosed

Basically it's a user error. I concede that it's something I would like to see detected automatically, but I've never figured out a way to do this. Sorry about this.

Robert Ramey

Note: See TracTickets for help on using tickets.