ASSIGCOND.CALLFunction call in assignment in conditional statementThe ASSIGCOND.CALL checker finds conditional statements in which the right part of an assignment expression is a function call. 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(int); 3 int qq(); 4 }; 5 void A::foo(int i) 6 { 7 if(i=qq()){} 8 } In the code example, Klocwork has flagged line 7 because the right side of the assignment expression in the if statement appears to be a function call. Fixed code example 11 class A{ 2 void foo(int); 3 int qq(); 4 }; 5 void A::foo(int i) 6 { 7 if((i==qq()) {} 8 } In this fixed code, the assignment operator has been replaced with the intended comparison operator. Fixed code example 21 class A{ 2 void foo(int); 3 int qq(); 4 }; 5 void A::foo(int i) 6 { 7 if((i=qq()) !=0) {} 8 } In this fixed code, brackets have been used to make the assignment syntax clear. Related checkers |