Fix #118
NEWS: * Switching endianness mid-byte no longer potentially re-reads bytes. * bit_offset now consistently refers to the number of bits already read. * HParsedTokens now have a bit_length field; this is a size_t. This may be removed for memory reasons. The bit writer has not yet been updated to match; the result of switching bit writer endianness in the middle of a byte remains undefined.
This commit is contained in:
parent
58af99ae40
commit
af73181cf4
12 changed files with 86 additions and 48 deletions
38
src/t_regression.c
Normal file
38
src/t_regression.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include "glue.h"
|
||||
#include "hammer.h"
|
||||
#include "test_suite.h"
|
||||
|
||||
static void test_bug118(void) {
|
||||
// https://github.com/UpstandingHackers/hammer/issues/118
|
||||
// Adapted from https://gist.github.com/mrdomino/c6bc91a7cb3b9817edb5
|
||||
|
||||
HParseResult* p;
|
||||
const uint8_t *input = (uint8_t*)"\x69\x5A\x6A\x7A\x8A\x9A";
|
||||
|
||||
#define MY_ENDIAN (BIT_BIG_ENDIAN | BYTE_LITTLE_ENDIAN)
|
||||
H_RULE(nibble, h_with_endianness(MY_ENDIAN, h_bits(4, false)));
|
||||
H_RULE(sample, h_with_endianness(MY_ENDIAN, h_bits(10, false)));
|
||||
#undef MY_ENDIAN
|
||||
|
||||
H_RULE(samples, h_sequence(h_repeat_n(sample, 3), h_ignore(h_bits(2, false)), NULL));
|
||||
|
||||
H_RULE(header_ok, h_sequence(nibble, nibble, NULL));
|
||||
H_RULE(header_weird, h_sequence(nibble, nibble, nibble, NULL));
|
||||
|
||||
H_RULE(parser_ok, h_sequence(header_ok, samples, NULL));
|
||||
H_RULE(parser_weird, h_sequence(header_weird, samples, NULL));
|
||||
|
||||
|
||||
p = h_parse(parser_weird, input, 6);
|
||||
g_check_cmp_int32(p->bit_length, ==, 44);
|
||||
h_parse_result_free(p);
|
||||
p = h_parse(parser_ok, input, 6);
|
||||
g_check_cmp_int32(p->bit_length, ==, 40);
|
||||
h_parse_result_free(p);
|
||||
}
|
||||
|
||||
void register_regression_tests(void) {
|
||||
g_test_add_func("/core/regression/bug118", test_bug118);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue