mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +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
1 changed files with 4 additions and 0 deletions
|
@ -222,6 +222,10 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE void discard_previously_peeked_bits(u8 count)
|
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_offset += count;
|
||||||
m_bit_count -= count;
|
m_bit_count -= count;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue