Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2004-13.7_a

In this section:
Synopsis

(Required) Boolean operations whose results are invariant shall not be permitted.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A comparison using ==, <, <=, >, or >= was found that always evaluates to true. This check is identical to RED-cmp-always.

Coding standards
CWE 571

Expression is Always True

MISRA C:2004 13.7

(Required) Boolean operations whose results are invariant shall not be permitted.

Code examples

The following code example fails the check and will give a warning:

int example(void) {
  int x = 42;

  if (x == 42) {  //always true
    return 0;
  }

  return 1;

}

The following code example passes the check and will not give a warning about this issue:

int example(void) {
  int x = 42;

  if (rand()) {
    x = 40;
  }

  if (x == 42) {  //OK - may not be true
    return 0;
  }

  return 1;

}