You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by dc...@apache.org on 2025/09/08 20:19:54 UTC

(cassandra-accord) branch CASSANDRA-20883_v2 created (now cef3cb40)

This is an automated email from the ASF dual-hosted git repository.

dcapwell pushed a change to branch CASSANDRA-20883_v2
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git


      at cef3cb40 CASSANDRA-20883: fixed a bug with the bit set when querying outside of the size

This branch includes the following new commits:

     new cef3cb40 CASSANDRA-20883: fixed a bug with the bit set when querying outside of the size

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


(cassandra-accord) 01/01: CASSANDRA-20883: fixed a bug with the bit set when querying outside of the size

Posted by dc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dcapwell pushed a commit to branch CASSANDRA-20883_v2
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git

commit cef3cb40552f01887d4bdc739c78acca4171c2a4
Author: David Capwell <dc...@apple.com>
AuthorDate: Mon Sep 8 13:19:07 2025 -0700

    CASSANDRA-20883: fixed a bug with the bit set when querying outside of the size
---
 .../src/main/java/accord/utils/LargeBitSet.java    |  2 +-
 .../src/main/java/accord/utils/SmallBitSet.java    |  2 ++
 .../test/java/accord/utils/SimpleBitSetTest.java   | 26 +++++++++++++++++-----
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/accord-core/src/main/java/accord/utils/LargeBitSet.java b/accord-core/src/main/java/accord/utils/LargeBitSet.java
index fbeae5bf..73309a05 100644
--- a/accord-core/src/main/java/accord/utils/LargeBitSet.java
+++ b/accord-core/src/main/java/accord/utils/LargeBitSet.java
@@ -320,7 +320,7 @@ public class LargeBitSet implements SimpleBitSet
     private int nextSetBitInternal(int i, int exclIndexBound, int ifNotFound)
     {
         Invariants.requireArgument(i >= 0);
-        Invariants.requireArgument(i <= size());
+        if (i >= size()) return -1;
 
         if (count == 0)
             return ifNotFound;
diff --git a/accord-core/src/main/java/accord/utils/SmallBitSet.java b/accord-core/src/main/java/accord/utils/SmallBitSet.java
index a0e692f9..6efc39de 100644
--- a/accord-core/src/main/java/accord/utils/SmallBitSet.java
+++ b/accord-core/src/main/java/accord/utils/SmallBitSet.java
@@ -77,6 +77,8 @@ public class SmallBitSet implements SimpleBitSet
     @Override
     public int nextSetBit(int fromIndex)
     {
+        if (fromIndex >= 64)
+            return -1;
         long bits = this.bits & bitsEqualOrGreater(fromIndex);
         if (bits == 0)
             return -1;
diff --git a/accord-core/src/test/java/accord/utils/SimpleBitSetTest.java b/accord-core/src/test/java/accord/utils/SimpleBitSetTest.java
index 6c750eaa..69eb5c58 100644
--- a/accord-core/src/test/java/accord/utils/SimpleBitSetTest.java
+++ b/accord-core/src/test/java/accord/utils/SimpleBitSetTest.java
@@ -64,6 +64,12 @@ class SimpleBitSetTest
         return new Property.SimpleCommand<>("NextSetBit(" + idx + ')', s2 -> s2.nextSetBit(idx));
     }
 
+    private static Property.Command<State, Void, ?> nextSetBitOutOfRange(RandomSource rs, State state)
+    {
+        int idx = rs.nextInt(state.size, Integer.MAX_VALUE);
+        return new Property.SimpleCommand<>("NextSetBitOutOfRange(" + idx + ')', s2 -> s2.nextSetBit(idx));
+    }
+
     @Test
     public void test()
     {
@@ -74,6 +80,7 @@ class SimpleBitSetTest
                                             .add(SimpleBitSetTest::clear)
                                             .add(SimpleBitSetTest::isEmpty)
                                             .add(SimpleBitSetTest::nextSetBit)
+                                            .add(SimpleBitSetTest::nextSetBitOutOfRange)
                                             .build());
     }
 
@@ -145,13 +152,20 @@ class SimpleBitSetTest
         public int nextSetBit(int fromIndex)
         {
             int expected;
-            for (expected = fromIndex; expected < size; expected++)
+            if (fromIndex >= size)
             {
-                if (model.get(expected))
-                    break;
-            }
-            if (expected == size)
                 expected = -1;
+            }
+            else
+            {
+                for (expected = fromIndex; expected < size; expected++)
+                {
+                    if (model.get(expected))
+                        break;
+                }
+                if (expected == size)
+                    expected = -1;
+            }
             int actual = sut.nextSetBit(fromIndex);
 
             Assertions.assertThat(actual).isEqualTo(expected);
@@ -167,7 +181,7 @@ class SimpleBitSetTest
         @Override
         public String toString()
         {
-            return sut.getClass().getSimpleName();
+            return sut.getClass().getSimpleName() + ", size=" + size;
         }
     }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org