]> git.cworth.org Git - apitrace/blobdiff - common/pickle.hpp
image: Make PNG writing an Image method.
[apitrace] / common / pickle.hpp
index 60694fa83d92d8da1e9891e6865574d13d7e0ea2..84b643a93ab7301c2e4fdbaa5520fa7bb8e176d9 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <ostream>
 #include <string>
+#include <limits>
 
 
 class PickleWriter
@@ -300,12 +301,20 @@ 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) {
-            ++c;
+        T sign;
+        if (std::numeric_limits<T>::is_signed) {
+            sign = l < 0 ? ~0 : 0;
+        } else {
+            sign = 0;
         }
+
+        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;