Skip to main content

IAR Embedded Workbench for RISC-V 3.40

RED-cmp-never

In this section:
Synopsis

A comparison using ==, <, <=, >, or >= is always false.

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A comparison using ==, <, <=, >, or >= is always false, based on the values of the arguments of the comparison operator. This often occurs because literal values or macros have been used on one or both sides of the operator. Double-check that the operands and the code logic are correct. This check is identical to MISRAC2004-13.7_b.

Coding standards
CWE 570

Expression is Always False

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 = 10;

  if (x < 10) {  //never true
    return 1;
  }

  return 0;
}

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

int example(int x) {

  if (x < 10) {  //OK - may be true
    return 1;
  }

  return 0;
}