[Issue 19338] std.bitmanip.BitArray.count gives segfault for empy BitArray

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 28 13:52:36 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19338

--- Comment #2 from Richard Palme <richardpalme5b at gmail.com> ---
The phobos implementation of this function is:

--------------------------------------------------------------------
size_t count()
{
    size_t bitCount;
    foreach (i; 0 .. fullWords)
        bitCount += countBitsSet(_ptr[i]);
    bitCount += countBitsSet(_ptr[fullWords] & endMask);
    return bitCount;
}
--------------------------------------------------------------------

My guess would be that for an empty BitArray, _ptr is null. count() then tries
to access _ptr[fullWords], which leads to the segfault.

--


More information about the Digitalmars-d-bugs mailing list