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

False positive in MISRA C++ 2008 Rule 6-5-6 #10

Open
d3lta-v opened this issue Oct 23, 2024 · 0 comments
Open

False positive in MISRA C++ 2008 Rule 6-5-6 #10

d3lta-v opened this issue Oct 23, 2024 · 0 comments

Comments

@d3lta-v
Copy link

d3lta-v commented Oct 23, 2024

Describe the bug
The bug is found in the checker for MISRA C++ 2008 Rule 6–5-6, which states that loop control variables in a for loop, other than the loop counter itself, should have the type bool to make the program easier to read. The analyzer seems to apply this rule to any loop control variable even if they are not changed inside the loop.

For example, the following snippet of code compares the loop counter i with a const size_t variable, which is guaranteed to never change:

void SerPort::ReadCallback(const uint8_t* buf, const size_t len) {
    for (size_t i=0; i<len; i++)
    ...

This is flagged by Analyze as a rule 6-5-6 violation, possibly due to the usage of the variable len within the loop condition, even though this is a const variable.

To Reproduce
Steps to reproduce the behavior:

  1. Analyze any code with a for loop that has a variable in the loop condition as stated above
  2. The analyzer software will report this as a 6-5-6 violation

Expected behavior
The violation should not be flagged by the software.

Desktop (please complete the following information):

  • OS: Fedora 40 running Analyze through Podman
  • Version: latest
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

No branches or pull requests

1 participant