Checkers:ASSIGCOND.GEN
From current
Reference > C/C++ checkers > ASSIGCOND.GEN
Assignment in conditional expression
The ASSIGCOND.GEN checker finds conditional statements that include an assignment expression.
Vulnerability and risk
This 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.
Code examples
Vulnerable code example
1 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, Insight has flagged line 8 because the if statement appears to include an assignment.
Fixed code example 1
1 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 2
1 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
External guidance
- CWE-480:Use of Incorrect Operator
- CWE-481:Assigning instead of Comparing
- EXP18-C:Do not perform assignments in conditional expressions


