mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-29 06:15:24 +00:00
bit_reader_c: fix get_bit_position/get_remaining_bits
for empty buffers
One side affect of the fixed bug was that trying to identify/mux an empty file (file with a size of 0) resulted in the following error message: > Error: buffer_c: num > m_filled. Should not have happened. Please > file a bug report.
This commit is contained in:
parent
1c7ad896a1
commit
c8cb86b8fb
@ -194,11 +194,11 @@ public:
|
||||
}
|
||||
|
||||
int get_bit_position() const {
|
||||
return (m_byte_position - m_start_of_data) * 8 + 8 - m_bits_valid;
|
||||
return (m_byte_position - m_start_of_data) * 8 + (m_bits_valid ? 8 - m_bits_valid : 0);
|
||||
}
|
||||
|
||||
int get_remaining_bits() const {
|
||||
return (m_end_of_data - m_byte_position) * 8 - 8 + m_bits_valid;
|
||||
return (m_end_of_data - m_byte_position) * 8 - (m_bits_valid ? 8 - m_bits_valid : 0);
|
||||
}
|
||||
|
||||
void skip_bits(std::size_t num) {
|
||||
|
@ -20,6 +20,15 @@ TEST(BitReader, Initialization) {
|
||||
EXPECT_FALSE(b.eof());
|
||||
}
|
||||
|
||||
TEST(BitReader, InitializationEmpty) {
|
||||
unsigned char value{};
|
||||
auto b = mtx::bits::reader_c{&value, 0};
|
||||
|
||||
EXPECT_EQ(0, b.get_bit_position());
|
||||
EXPECT_EQ(0, b.get_remaining_bits());
|
||||
EXPECT_TRUE(b.eof());
|
||||
}
|
||||
|
||||
TEST(BitReader, GetBit) {
|
||||
unsigned char value[4];
|
||||
put_uint32_be(value, 0xf7234a81);
|
||||
|
Loading…
Reference in New Issue
Block a user