]> p2p-next.cs.pub.ro Git - swift-upb.git/commitdiff
Fixed integer overflow in method bin64_t::to().
authorAlexander G. Pronchenkov <the.zett@gmail.com>
Tue, 26 Jan 2010 11:35:42 +0000 (16:35 +0500)
committerAlexander G. Pronchenkov <the.zett@gmail.com>
Tue, 26 Jan 2010 11:44:45 +0000 (16:44 +0500)
Symptom: ALL.left() == ALL.right() == ALL

bin64.h

diff --git a/bin64.h b/bin64.h
index 9045fe7bace5ea58c76d6f14819f59a2a71374f4..3550f22a223672b6aedd00896628617c93d64e3b 100644 (file)
--- a/bin64.h
+++ b/bin64.h
@@ -93,10 +93,10 @@ struct bin64_t {
     bin64_t to (bool right) const {
         if (!(v&1))
             return NONE;
-        uint64_t tb = tail_bit()>>1;
+        uint64_t tb = ((tail_bits() >> 1) + 1) >> 1;
         if (right)
-            tb |= (tb<<1);
-        return bin64_t(v^tb);
+            return bin64_t(v + tb);
+        return bin64_t(v ^ tb);
     }
 
     /** Get the left child bin. */