Skip to content

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

Description

@d3lta-v

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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