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 9045fe7..3550f22 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. */