Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper argument types result in Undefined Behavior #5

Closed
vpetrigo opened this issue Sep 28, 2023 · 0 comments · Fixed by #6
Closed

Improper argument types result in Undefined Behavior #5

vpetrigo opened this issue Sep 28, 2023 · 0 comments · Fixed by #6

Comments

@vpetrigo
Copy link
Contributor

Hello,

There is an issue with argument types for the whole set of CRC functions. For example, the following input buffer would result in the improper CRC calculation:

    const uint8_t buffer[] = {0xb0, 0, 0, 0, 0, 0, 0};

    expect = 0x1a;
    EXPECT_EQ(crc8_lsb((const char *)buffer, sizeof(buffer)), expect);

On my machine the test fails with the following issue:

failed: Expect:3f == Actual:1a

The issue with signed characters that current interface expects: 0xb0 is -80 as char. Thus, this code leads to negative array index access:

crc = crc8tab_lsb[crc ^ *buf++];
// On the veriy first step crc ^ *buf = -80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant