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.CALL

Function call in assignment in conditional statement

The ASSIGCOND.CALL checker finds conditional statements in which the right part of an assignment expression is a function call.

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(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 1

1  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 2

1  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