From 8879d0cbc1289c842272aa6867625f418ad062f5 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 6 Aug 2013 08:30:33 +0000 Subject: [PATCH] Fix deserialization when limb size is larger than that of the original archive. [SVN r85220] --- include/boost/multiprecision/cpp_int/serialize.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/boost/multiprecision/cpp_int/serialize.hpp b/include/boost/multiprecision/cpp_int/serialize.hpp index faea5eba..44378fa8 100644 --- a/include/boost/multiprecision/cpp_int/serialize.hpp +++ b/include/boost/multiprecision/cpp_int/serialize.hpp @@ -55,11 +55,12 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::false_ const&, for(std::size_t i = 0; i < limb_count; ++i) { pl[i] = 0; - for(std::size_t j = 0; j < sizeof(limb_type); ++j) + for(std::size_t j = 0; (j < sizeof(limb_type)) && byte_count; ++j) { unsigned char byte; ar & byte; pl[i] |= static_cast(byte) << (j * CHAR_BIT); + --byte_count; } } if(s != val.sign()) @@ -99,9 +100,9 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::true_ const&, bool s; typename Int::local_limb_type l = 0; ar & s; - std::size_t limb_count; - ar & limb_count; - for(std::size_t i = 0; i < limb_count; ++i) + std::size_t byte_count; + ar & byte_count; + for(std::size_t i = 0; i < byte_count; ++i) { unsigned char b; ar & b;