Opened 13 years ago
Closed 11 years ago
#3365 closed Bugs (fixed)
Serialization of multi_index_container is non portable.
Reported by: | Owned by: | Joaquín M López Muñoz | |
---|---|---|---|
Milestone: | Boost 1.40.0 | Component: | multi_index |
Version: | Boost 1.38.0 | Severity: | Problem |
Keywords: | multi_index_container serialization, multi_index | Cc: | mailinglists@… |
Description
multi_index_container save and load member-functions use type "std::size_t" to serialize a container's size instead of boost::serialization::collection_size_type. It may cause some problems when portable binary archives are used, because std::size_t has different size in different platforms. boost::serialization::collection_size_type can be treated specially by portable archive implementations: collection_size_type used in the serialization implementation for the standart containers.
Change History (6)
comment:1 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Ilia, just fixed the problem in changeset
https://svn.boost.org/trac/boost/changeset/55994
I'd appreciate if you could check everything's OK on your side.
comment:3 by , 11 years ago
Cc: | added |
---|---|
Resolution: | fixed |
Severity: | Cosmetic → Problem |
Status: | closed → reopened |
The changeset may fix this problem (haven't checked), but line 667 (of this changeset) might cause data truncation under x64 bit and a compiler warning.
serialization::collection_size_type s; detail::serialization_version<value_type> value_version; if(version<1){ std::size_t sz; ar>>serialization::make_nvp("count",sz); s=sz; /***** Error here *****/ }
With x64 bit compilation (Visual Studio 2008, boost 1.44) collection_size_type is unsigned int (32 Bit), whereas size_t is an unsigned long (64 Bit). The assignment s=sz gets truncated and issues a warning
boost\boost/multi_index_container.hpp(673) : error C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
Since our project treats this warning as an error, the code does not compile.
The patch here is straightforward: simply cast the result. There is nothing we can do in this case anyway and also it is pretty unlikely that any user in the world will serialise more than 232 items.
@@ -670,7 +670,7 @@ if(version<1){ std::size_t sz; ar>>serialization::make_nvp("count",sz); - s=sz; + s=(serialization::collection_size_type)sz; } else{ ar>>serialization::make_nvp("count",s);
comment:4 by , 11 years ago
Hi Hajo,
Please check whether
https://svn.boost.org/trac/boost/changeset/75643
solves the issue. Thank you!
comment:5 by , 11 years ago
Hi Joaquin, yes, that should solve the issue. Thanks. And thanks for your work :-) (fixed in 1.49) You can close this ticket again...
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [55994]) fixed #3365