Skip to content

Commit 291de3d

Browse files
committed
Fix bitseq.SetAnyInRange
- size 1 range is a valid input Signed-off-by: Alessandro Boch <aboch@docker.com>
1 parent c1f6d91 commit 291de3d

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

bitseq/sequence.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (h *Handle) getCopy() *Handle {
197197

198198
// SetAnyInRange atomically sets the first unset bit in the specified range in the sequence and returns the corresponding ordinal
199199
func (h *Handle) SetAnyInRange(start, end uint64) (uint64, error) {
200-
if end-start <= 0 || end >= h.bits {
200+
if end < start || end >= h.bits {
201201
return invalidPos, fmt.Errorf("invalid bit range [%d, %d]", start, end)
202202
}
203203
if h.Unselected() == 0 {

bitseq/sequence_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,6 @@ func TestSetInRange(t *testing.T) {
639639
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
640640
}
641641

642-
if o, err := hnd.SetAnyInRange(5, 5); err == nil {
643-
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
644-
}
645-
646642
if o, err := hnd.SetAnyInRange(0, numBits); err == nil {
647643
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
648644
}
@@ -692,6 +688,11 @@ func TestSetInRange(t *testing.T) {
692688
t.Fatalf("Unexpected failure: %v", err)
693689
}
694690

691+
// set one bit using the set range with 1 bit size range
692+
if _, err := hnd.SetAnyInRange(uint64(163*blockLen-1), uint64(163*blockLen-1)); err != nil {
693+
t.Fatal(err)
694+
}
695+
695696
// create a non multiple of 32 mask
696697
hnd, err = NewHandle("", nil, "", 30)
697698
if err != nil {

0 commit comments

Comments
 (0)