Skip to content

Bitv internal nbits counter silently overflows for huge bitvs on 32-bit platforms #16958

Closed
@huonw

Description

@huonw
use std::collections::Bitv;
fn main() {
let mut bitv = Bitv::with_capacity((!0u32) as uint, false);

bitv.grow(1, true);

println!("{}", bitv.get(0));
}
task '<main>' failed at 'assertion failed: i < self.nbits', ...

since the grow is wrapping the internal (32-bit) uint. (A naive bit counter for a bit vector needs 3 additional bits over a uint to be guaranteed to work always.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions