CXX.POSSIBLE_COPY_PASTE.LOGICAL_OP.CMP_SAME_OBJECT
Possible copy-paste error: An object should not be logically compared to itself.
This checker reports defects when the same objects are compared by using a logical operator.
Vulnerable code example
1 int f1() { 2 bool isAFruit = false; 3 const int ORANGE = 8; 4 5 if (ORANGE == ORANGE) 6 isAFruit = true; 7 8 return 0; 9 }
In the above example, line 5 is noncompliant as an int object ORANGE is compared with itself. Klocwork reports a CXX.POSSIBLE_COPY_PASTE.LOGICAL_OP.CMP_SAME_OBJECT defect at line 5 with a message, indicating, "Possible copy-paste error: An object should not be logically compared to itself."
Fixed code example
1 int f1() { 2 bool isAFruit = false; 3 const int ORANGE = 8; 4 5 if (ORANGE == 8) 6 isAFruit = true; 7 8 return 0; 9 }
In the fixed example, Klocwork no longer reports the defect CXX.POSSIBLE_COPY_PASTE.LOGICAL_OP.CMP_SAME_OBJECT at line 5.