---
title: "CWE-482: Comparing instead of Assigning"
url: https://radicalnotion.ai/cwe/cwe-482
type: cwe
description: "The code uses an operator for comparison when the intention was to perform an assignment."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-482: Comparing instead of Assigning

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Low
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

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

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | In many languages, the compare statement is very close in appearance to the assignment statement; they are often confused. This bug primarily originates from a typo. |

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability, Integrity | Unexpected State | The assignment will not take place, which should cause obvious program execution problems. |

## Potential mitigations

### Testing

Many IDEs and static analysis products will detect this problem.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

### Automated Static Analysis - Source Code

An Integrated Development Environment (IDE) or linter can report or highlight this weakness.

## Demonstrative examples

### Example 1

The following example demonstrates the weakness.

Bad code:

```java
void called(int foo) {
    foo==1;
    if (foo==1) System.out.println("foo\n");
}
int main() {

    called(2);
    return 0;
}
```

### Example 2

The following C/C++ example shows a simple implementation of a stack that includes methods for adding and removing integer values from the stack. The example uses pointers to add and remove integer values to the stack array variable.

Bad code:

```c
#define SIZE 50
int *tos, *p1, stack[SIZE];

void push(int i) {
    p1++;
    if(p1==(tos+SIZE)) {

        // Print stack overflow error message and exit
    }
    *p1 == i;
}

int pop(void) {
    if(p1==tos) {

        // Print stack underflow error message and exit
    }
    p1--;
    return *(p1+1);
}

int main(int argc, char *argv[]) {

    // initialize tos and p1 to point to the top of stack
    tos = stack;
    p1 = stack;
    // code to add and remove items from stack
    ...
    return 0;
}
```

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-480](https://radicalnotion.ai/cwe/cwe-480) | Use of Incorrect Operator |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Comparing instead of assigning | - | - |
| Software Fault Patterns | Unused Entities | SFP2 | - |

## Frequently asked questions

### What is CWE-482?

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

### How do you prevent CWE-482?

Many IDEs and static analysis products will detect this problem.

### How is CWE-482 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-482?

Exploiting CWE-482 can lead to: Unexpected State.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/482.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-482). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
