analyze icon indicating copy to clipboard operation
analyze copied to clipboard

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

Open d3lta-v opened this issue 1 year ago • 0 comments

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

d3lta-v avatar Oct 23 '24 03:10 d3lta-v