tlk00 / BitMagic

BitMagic Library
http://bitmagic.io
Other
412 stars 48 forks source link

Fix setting wrong bit in bitblock for import_block #78

Closed yrivardmulrooney closed 3 months ago

yrivardmulrooney commented 3 months ago

import_block uses the array's first element's bit position instead of the one specified by start, which can lead to the wrong bit being set in the bitblock in a case where a single bit is to be set for the block and the bit is not the first element of the array to be imported.

Minimal example to reproduce the issue:

bm::bvector<> bv;
bv.set(65540);
bv.optimize();
{
    bm::bvector<>::bulk_insert_iterator it(bv);
    *it = 0;
    *it = 65540;
}

assert(bv.count() == 2);
assert(bv.get_bit(0));
assert(bv.get_bit(65540));

This example produces a bvector with the bits 0, 65536 and 65540 set, instead of the expected 0 and 65540.

tlk00 commented 3 months ago

Good catch, thank you! Integrated both patch and the unit test.