Skip to content

Commit 8baa69e

Browse files
committed
Fix, static IBitView::set() doesn't set all requested bits.
1 parent e66254f commit 8baa69e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

libs/basic/bitspan.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static void set(void * vdst, size_t dpos, size_t dcnt) {
485485
}
486486
auto mask = (unsigned char) (255 >> dpos);
487487
apply<Op, unsigned char>(dst, nullptr, mask);
488-
dcnt -= dpos;
488+
dcnt -= 8 - dpos;
489489
dpos = 0;
490490
dst += 1;
491491
}
@@ -854,14 +854,16 @@ BitSpan & BitSpan::set() {
854854

855855
//===========================================================================
856856
BitSpan & BitSpan::set(size_t bitpos) {
857+
assert(bitpos < bits());
857858
auto pos = bitpos / kWordBits;
858-
assert(pos < m_size);
859859
m_data[pos] |= bitmask(bitpos);
860860
return *this;
861861
}
862862

863863
//===========================================================================
864864
BitSpan & BitSpan::set(size_t bitpos, size_t bitcount) {
865+
if (bitcount == 1)
866+
return set(bitpos);
865867
assert(bitpos < bits());
866868
if (bitcount > bits() - bitpos)
867869
bitcount = bits() - bitpos;
@@ -937,6 +939,8 @@ BitSpan & BitSpan::reset(size_t bitpos) {
937939

938940
//===========================================================================
939941
BitSpan & BitSpan::reset(size_t bitpos, size_t bitcount) {
942+
if (bitcount == 1)
943+
return reset(bitpos);
940944
assert(bitpos < bits());
941945
if (bitcount > bits() - bitpos)
942946
bitcount = bits() - bitpos;
@@ -961,6 +965,8 @@ BitSpan & BitSpan::flip(size_t bitpos) {
961965

962966
//===========================================================================
963967
BitSpan & BitSpan::flip(size_t bitpos, size_t bitcount) {
968+
if (bitcount == 1)
969+
return flip(bitpos);
964970
::apply<kFlip, uint64_t>(m_data, m_size, nullptr, bitpos, bitcount);
965971
return *this;
966972
}

0 commit comments

Comments
 (0)