Menu

#611 PBitArray::GetLength() returns length in bits

Stable_Branch
open
None
5
2022-07-27
2022-07-27
d153859
No

PTLib 2.18.8 release bundle.

When calling GetLength() on a PBitArray object, a value in bits is returned, while the documentation says: "Retrun the length in bytes for the array".

This method is derived from PAbstractArray::GetLength() and is defined as:

return elementSize*GetSize();

elementSize is 1 and virtual GetSize() returns bit count for PBitArray (as expected). So we get GetLength() in bits, not in bytes.

Strictly speaking, elementSize should be 1/8 (bytes) for PBitArray, but fractions can't be used here. And this finally produces incorrect values returned by GetLength().

Suggested solution:
Override GetLength() for PBitArray class as:

PINDEX PBitArray::GetLength() const
{
  return PBYTEArray::GetSize();
}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB