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:
Tim Schumacher 2023-04-27 11:33:08 +02:00 committed by Jelle Raaijmakers
parent dffef6bb71
commit 56d861ebe0

View file

@ -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;
}