From 43e8b4d5a0fde24cfa2b1c102f07e2ff81e1c1f9 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 7 Oct 2024 17:20:51 -0400 Subject: [PATCH 1/3] issue 174 --- bitset.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bitset.go b/bitset.go index 2e8d9ce..2f1f7ef 100644 --- a/bitset.go +++ b/bitset.go @@ -106,8 +106,16 @@ func From(buf []uint64) *BitSet { return FromWithLength(uint(len(buf))*64, buf) } -// FromWithLength constructs from an array of words and length. +// FromWithLength constructs from an array of words and length in bits. +// This function is for advanced users, most users should prefer +// the From function. +// As a user of FromWithLength, you are responsible for ensuring +// that the length is correct: your slice should have length at +// least (len+63)/64 in 64-bit words. func FromWithLength(len uint, set []uint64) *BitSet { + if uint(len(set)) < wordsNeeded(len) { + panic("BitSet.FromWithLength: slice is too short") + } return &BitSet{len, set} } From c2536d3054d32e07ffe639dac129348047ae4d4c Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 7 Oct 2024 17:23:22 -0400 Subject: [PATCH 2/3] fix --- bitset.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bitset.go b/bitset.go index 2f1f7ef..4d98126 100644 --- a/bitset.go +++ b/bitset.go @@ -112,11 +112,11 @@ func From(buf []uint64) *BitSet { // As a user of FromWithLength, you are responsible for ensuring // that the length is correct: your slice should have length at // least (len+63)/64 in 64-bit words. -func FromWithLength(len uint, set []uint64) *BitSet { - if uint(len(set)) < wordsNeeded(len) { +func FromWithLength(length uint, set []uint64) *BitSet { + if len(set) < wordsNeeded(length) { panic("BitSet.FromWithLength: slice is too short") } - return &BitSet{len, set} + return &BitSet{length, set} } // Bytes returns the bitset as array of 64-bit words, giving direct access to the internal representation. From 2ba49f65a4028d95f47558f467ae32e814555ad2 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 7 Oct 2024 17:26:22 -0400 Subject: [PATCH 3/3] fix --- bitset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitset.go b/bitset.go index 4d98126..c860986 100644 --- a/bitset.go +++ b/bitset.go @@ -111,7 +111,7 @@ func From(buf []uint64) *BitSet { // the From function. // As a user of FromWithLength, you are responsible for ensuring // that the length is correct: your slice should have length at -// least (len+63)/64 in 64-bit words. +// least (length+63)/64 in 64-bit words. func FromWithLength(length uint, set []uint64) *BitSet { if len(set) < wordsNeeded(length) { panic("BitSet.FromWithLength: slice is too short")