openxc / bitfield-c

Bit array parsing and encoding utility library in C
BSD 3-Clause "New" or "Revised" License
92 stars 51 forks source link

Bug in macro "PREPARE_FIRST_COPY" #6

Open zwxdlut opened 4 years ago

zwxdlut commented 4 years ago

Add test case in "test_set_bitfield": ..... START_TEST (test_set_bitfield) { uint8_t data[4] = {0}; fail_unless(set_bitfield(0x12, 0, 8, data, sizeof(data))); fail_unless(set_bitfield(bitmask(3), 10, 3, data, sizeof(data))); ck_assert_int_eq(data[0], 0x12); ck_assert_int_eq(data[1], 0x38); // Add test case fail_unless(set_bitfield(0x1, 23, 1, data, sizeof(data))); ck_assert_int_eq(data[2], 0x1); // Should be 0x1 fail_unless(set_bitfield(0x1, 21, 2, data, sizeof(data))); ck_assert_int_eq(data[2], 0x3); // Should be 0x3 } END_TEST ..... As above, when call "set_bitfield(0x1, 21, 2, data, sizeof(data));", data2 will be set to "0" by macro "PREPARE_FIRST_COPY", and then the result will be 0x2. Test failed as follow:

90%: Checks: 10, Failures: 1, Errors: 0 tests/bitfield_tests.c:39:F:core:test_set_bitfield:0: Assertion 'data[2]==0x3' failed: data[2]==2, 0x3==3