mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +00:00
AK: Prevent bit counter underflows in the new BitStream
Our current `peek_bits` function allows retrieving more bits than we can actually provide, so whenever someone discards the requested bit count afterwards we were underflowing the value instead.
This commit is contained in:
parent
dffef6bb71
commit
56d861ebe0
|
@ -222,6 +222,10 @@ public:
|
|||
|
||||
ALWAYS_INLINE void discard_previously_peeked_bits(u8 count)
|
||||
{
|
||||
// We allow "retrieving" more bits than we can provide, but we need to make sure that we don't underflow the current bit counter.
|
||||
if (count > m_bit_count)
|
||||
count = m_bit_count;
|
||||
|
||||
m_bit_offset += count;
|
||||
m_bit_count -= count;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue