Skip to content

Commit e60021e

Browse files
mafintoshHDegroote
andauthored
p might be undef if setting false (#744)
* p might be undef if setting false * Add test --------- Co-authored-by: hdegroote <[email protected]>
1 parent d6ec6ee commit e60021e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/bitfield.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ module.exports = class Bitfield {
350350
p = this._pages.set(i, new BitfieldPage(i, s))
351351
}
352352

353-
const offset = p.index * BITS_PER_PAGE
353+
const offset = i * BITS_PER_PAGE
354354
const last = Math.min(end - offset, BITS_PER_PAGE)
355355
const range = last - j
356356

test/bitfield.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ test('bitfield - set range on page boundary', async function (t) {
288288
t.is(b.findFirst(true, 2048), 2048)
289289
})
290290

291+
test('bitfield - set false range on page that does not yet exist', async function (t) {
292+
const s = await createStorage(t)
293+
const b = await Bitfield.open(s, 0)
294+
295+
t.execution(() => b.setRange(32769, 32780, false), 'does not throw')
296+
})
297+
291298
test('set last bits in segment and findFirst', async function (t) {
292299
const s = await createStorage(t)
293300
const b = await Bitfield.open(s, 0)

0 commit comments

Comments
 (0)