ASSIGCOND.GENAssignment in conditional expressionThe ASSIGCOND.GEN checker finds conditional statements that include an assignment expression. Vulnerability and riskThis checker typically finds syntax errors, usually cases in which an assignment operator is used mistakenly instead of a comparison operator. If the error isn't corrected, unintended program behavior is likely to occur. Vulnerable code example1 class A{ 2 void foo(); 3 }; 4 void A::foo() 5 { 6 int i = 1; 7 int j = 0; 8 if(i = j) j++; 9 } In the code example, Klocwork has flagged line 8 because the if statement appears to include an assignment. Fixed code example 11 class A{ 2 void foo(); 3 }; 4 void A::foo() 5 { 6 int i = 1; 7 int j = 0; 8 if((i == j)) j++; 9 } In this fixed code, the assignment operator has been replaced with the intended comparison operator. Fixed code example 21 class A{ 2 void foo(); 3 }; 4 void A::foo() 5 { 6 int i = 1; 7 int j = 0; 8 if((i=qq()) !=0) j++; 9 } In this fixed example, brackets have been used to make the assignment syntax clear. Related checkers |