# VNX-480: Use of Incorrect Operator

Reports operators that compile but do not do what the line means. Java.

| Field | Value |
|---|---|
| Rule ID | `VNX-480` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | C, C++, Java |
| CWE | [CWE-480](https://cwe.mitre.org/data/definitions/480.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `wrong-operator` `cwe-480` |
| Source | [`internal/sast/rules/vnx-480.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-480.rego) |

## Overview

VNX-480 maps to [CWE-480: Use of Incorrect Operator](https://cwe.mitre.org/data/definitions/480.html). Each shape below compiles, usually without a warning, and gives the wrong answer:

- **Java String identity:** `role == "admin"` compares references. It is true for interned literals in tests and false for the same text read from a request, so a check that passes in development fails (or passes) in production.
- **Java BigDecimal identity:** `total == BigDecimal.ZERO` is false for `new BigDecimal("0.00")`.
- **C string literal:** `argv[1] == "--help"` compares two addresses.
- **C/C++ mask precedence:** `flags & PERM_WRITE == 0` parses as `flags & (PERM_WRITE == 0)`, which is always 0.
- **Transposed compound assignment (C/C++/Java):** `total =+ n` assigns `+n` instead of adding it.

Not reported: `equals()`, `compareTo()`, `strcmp()`, comparisons with `null`, char literals, `std::string == "..."` in C++ (which compares content; a `.h` header that uses `std::`, `class`, `namespace` or `template` counts as C++), parenthesised masks `(flags & MASK) == v`, `x = -n` written with a space, and operators inside strings and comments. An assignment used as a condition (`if (x = y)`) is reported by VNX-481. A Java String compared with a string literal (`role == "admin"`) is reported by [VNX-597](/sast/rules/vnx-597.md), so the same line is not reported twice; this rule keeps it only in a file that never names the `String` type, which VNX-597 needs.

## What gets flagged

```java
return total == BigDecimal.ZERO;        // FLAGGED
total =+ n;                             // FLAGGED
```

```c
if (argc > 1 && argv[1] == "--help")    /* FLAGGED */
if (flags & PERM_WRITE == 0)            /* FLAGGED */
```

## What is not flagged

```java
return role == "admin";                 // reported by VNX-597
return "admin".equals(role);
return total.compareTo(BigDecimal.ZERO) == 0;
```

```c
if ((flags & PERM_WRITE) == 0)
if (strcmp(mode, "rw") == 0)
```

## Remediation

1. Compare Java strings with `equals()` (constant first) and BigDecimal with `compareTo()` or `signum()`.
2. Compare C strings with `strcmp()`/`strncmp()`.
3. Parenthesise bitwise tests: `(flags & MASK) == value`.
4. Write compound assignments as `+=` / `-=`.

## References

- [CWE-480: Use of Incorrect Operator](https://cwe.mitre.org/data/definitions/480.html)
- [CWE-597: Use of Wrong Operator in String Comparison](https://cwe.mitre.org/data/definitions/597.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-480
// nosec vnx-480
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-480 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
