VariantDraft

CWE-481Assigning instead of Comparing

Category: other

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.

Common consequences· 1

  • Other — Alter Execution Logic

Potential mitigations· 1

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

References

  1. https://cwe.mitre.org/data/definitions/481.html

Related by meaning· 6

Nearest entities by semantic similarity across the cs-graph corpus.

CWE
Comparing instead of Assigning
CWE
Floating Point Comparison with Incorrect Operator
CWE
Assignment to Variable without Use
CWE
Excessive Use of Unconditional Branching
CWE
Insufficient Control Flow Management
CWE
Use of Incorrect Operator
Sourced from MITRE CWE 4.20. Curated for EU compliance use cases by Adam Lundqvist, Founder at SQUR.