Skip to content

{Small,}BitVector.reset(unsigned I, unsigned E) has off-by-one error #120898

@natanelh-mobileye

Description

@natanelh-mobileye

consider the following crashing code:

SmallBitVector BV(31, true);
BV.reset(30, 32);

expected behavior: bits 30, 31 are reset
actual behavior: assertion crash:

    at llvm-project/llvm/include/llvm/ADT/SmallBitVector.h:420
420	    assert(E <= size() && "Attempted to reset out-of-bounds range!");

it should check E <= size() + 1 since the end is not included in the range (at least according to the docs).
I am not good enough with bits and bytes to solve the algorithm however and a dumb change of adding one in that check may or may not cause UB later without special handling.

Smae error happens with BitVector with the same assertion. this is a classic off-by-one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:adtquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions