Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

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.

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, Klocwork 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