Skip to content

Bug in macro "PREPARE_FIRST_COPY" #6

@zwxdlut

Description

@zwxdlut

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions