Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langc
int a = 2;
int b = 2;
int c = 2;
/* ... */
if (a < b < c) /* Misleading,; likely bug */
/* ... */
if (a == b == c) /* Misleading,; likely bug */

The expression a < b < c evaluates to true rather than, as its author probably intended, to false, and the expression a == b == c evaluates to false rather than, as its author probably intended, to true.

...

Code Block
bgColor#ccccff
langc
if ( (a < b) && (b < c) ) /* Clearer, and probably what was intended */
/* ... */
if ( (a == b) && (a == c) ) /* Ditto */

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP13-C

lowLow

unlikelyUnlikely

mediumMedium

P2

L3

Automated Detection

Tool

Version

Checker

Description

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.EXP13

Fully implemented

GCC

Include Page
GCC_V
GCC_V

 

Option -Wparentheses warns if a comparison like x<=y<=z appears; this warning is also enabled by -Wall

PRQA QA-C
Include Page
PRQA_V
PRQA_V

3392
3401
4111
4112
4113

Fully implemented

...