From d64e5b2bcd7c7b84a87d3d25786216d1594ce0dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 5 Oct 2012 20:55:28 +0100 Subject: [PATCH] Fix pickling of long integers. shifting more than the number of bits in the type yields undefined results. --- common/pickle.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/pickle.hpp b/common/pickle.hpp index 60694fa..41667e6 100644 --- a/common/pickle.hpp +++ b/common/pickle.hpp @@ -300,12 +300,15 @@ protected: return; } - unsigned c = 1; // Same as l >> (8 * sizeof l), but without the warnings T sign = l < 0 ? ~0 : 0; - while ((l >> (8 * c)) != sign) { + + T sl = l; + unsigned c = 0; + do { ++c; - } + } while (sl >>= 8 != sign); + // Add an extra byte if sign bit doesn't match if (((l >> (8 * c - 1)) & 1) != ((l >> (8 * sizeof l - 1)) & 1)) { ++c; -- 2.43.0