CWE Database
/

CWE-481

Back to CWE list

CWE-481

Assigning instead of Comparing

Variant
Draft

Description

The code uses an operator for assignment when the intention was to perform a comparison.

In many languages the compare statement is very close in appearance to the assignment statement and are often confused. This bug is generally the result of a typo and usually causes obvious problems with program execution. If the comparison is in an if statement, the if statement will usually evaluate the value of the right-hand side of the predicate.

Parent Weaknesses (ChildOf)

Related Weaknesses

Common Consequences

Scope

Other

Impact

Alter Execution Logic

Potential Mitigations

Implementation

Place constants on the left. If one attempts to assign a constant with a variable, the compiler will produce an error.

Applicable Platforms

C
C++
Java
C#

Security Training

Train your team to recognize and prevent security threats with our comprehensive security awareness program.

Start Training

Vulnerability Scanning

Discover vulnerabilities in your applications and infrastructure before attackers do.

Scan Now