From 291de3dfcf9947c29c40ede4da09923c3a614bcd Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Tue, 13 Sep 2016 11:52:12 -0700 Subject: [PATCH] Fix bitseq.SetAnyInRange - size 1 range is a valid input Signed-off-by: Alessandro Boch --- bitseq/sequence.go | 2 +- bitseq/sequence_test.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bitseq/sequence.go b/bitseq/sequence.go index 550bcbb825..fb99944098 100644 --- a/bitseq/sequence.go +++ b/bitseq/sequence.go @@ -197,7 +197,7 @@ func (h *Handle) getCopy() *Handle { // SetAnyInRange atomically sets the first unset bit in the specified range in the sequence and returns the corresponding ordinal func (h *Handle) SetAnyInRange(start, end uint64) (uint64, error) { - if end-start <= 0 || end >= h.bits { + if end < start || end >= h.bits { return invalidPos, fmt.Errorf("invalid bit range [%d, %d]", start, end) } if h.Unselected() == 0 { diff --git a/bitseq/sequence_test.go b/bitseq/sequence_test.go index 339f5928ef..4ef3bbb6fe 100644 --- a/bitseq/sequence_test.go +++ b/bitseq/sequence_test.go @@ -639,10 +639,6 @@ func TestSetInRange(t *testing.T) { t.Fatalf("Expected failure. Got success with ordinal:%d", o) } - if o, err := hnd.SetAnyInRange(5, 5); err == nil { - t.Fatalf("Expected failure. Got success with ordinal:%d", o) - } - if o, err := hnd.SetAnyInRange(0, numBits); err == nil { t.Fatalf("Expected failure. Got success with ordinal:%d", o) } @@ -692,6 +688,11 @@ func TestSetInRange(t *testing.T) { t.Fatalf("Unexpected failure: %v", err) } + // set one bit using the set range with 1 bit size range + if _, err := hnd.SetAnyInRange(uint64(163*blockLen-1), uint64(163*blockLen-1)); err != nil { + t.Fatal(err) + } + // create a non multiple of 32 mask hnd, err = NewHandle("", nil, "", 30) if err != nil {