]> git.cworth.org Git - apitrace/commitdiff
Fix pickling of long integers.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 5 Oct 2012 19:55:28 +0000 (20:55 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 5 Oct 2012 19:55:28 +0000 (20:55 +0100)
shifting more than the number of bits in the type yields undefined results.

common/pickle.hpp

index 60694fa83d92d8da1e9891e6865574d13d7e0ea2..41667e653783be3bf934ceba9a11afaaba373615 100644 (file)
@@ -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;