---
title: "CWE-783: Operator Precedence Logic Error"
url: https://radicalnotion.ai/cwe/cwe-783
type: cwe
description: "The product uses an expression in which operator precedence causes incorrect logic to be used."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-783: Operator Precedence Logic Error

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

## Description

The product uses an expression in which operator precedence causes incorrect logic to be used.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | Logic errors related to operator precedence may cause problems even during normal operation, so they are probably discovered quickly during the testing phase. If testing is incomplete or there is a strong reliance on manual review of the code, then these errors may not be discovered before the software is deployed. |

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality, Integrity, Availability | Varies by Context, Unexpected State | While often just a bug, operator precedence logic errors can have serious consequences if they are used in security-critical code, such as making an authentication decision. The consequences will vary based on the context surrounding the incorrect precedence. In a security decision, violations of integrity or confidentiality are the most likely results. Otherwise, a crash may occur due to the software reaching an unexpected state. |

## Potential mitigations

### Implementation

Regularly wrap sub-expressions in parentheses, especially in security-critical code.

## 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

## Demonstrative examples

### Example 1

In the following example, the method validateUser makes a call to another method to authenticate a username and password for a user and returns a success or failure code.

Bad code:

```c
#define FAIL 0
#define SUCCESS 1

...

int validateUser(char *username, char *password) {

    int isUser = FAIL;

    // call method to authenticate username and password

    // if authentication fails then return failure otherwise return success
    if (isUser = AuthenticateUser(username, password) == FAIL) {
        return isUser;
    }
    else {
        isUser = SUCCESS;
    }

    return isUser;
}
```

Good code:

```c
...

if ((isUser = AuthenticateUser(username, password)) == FAIL) {

...
```

However, the method that authenticates the username and password is called within an if statement with incorrect operator precedence logic. Because the comparison operator "==" has a higher precedence than the assignment operator "=", the comparison operator will be evaluated first and if the method returns FAIL then the comparison will be true, the return variable will be set to true and SUCCESS will be returned. This operator precedence logic error can be easily resolved by properly using parentheses within the expression of the if statement, as shown below.

### Example 2

In this example, the method calculates the return on investment for an accounting/financial application. The return on investment is calculated by subtracting the initial investment costs from the current value and then dividing by the initial investment costs.

Bad code:

```java
public double calculateReturnOnInvestment(double currentValue, double initialInvestment) {

    double returnROI = 0.0;

    // calculate return on investment
    returnROI = currentValue - initialInvestment / initialInvestment;

    return returnROI;
}
```

Good code:

```java
...

returnROI = (currentValue - initialInvestment) / initialInvestment;

...
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2026-7270 | Chain: calculation expression does not use parentheses to address operator precedence (CWE-783), causing an incorrect calculation (CWE-682) leading to a buffer overflow (CWE-787). |
| CVE-2008-2516 | Authentication module allows authentication bypass because it uses "(x = call(args) == SUCCESS)" instead of "((x = call(args)) == SUCCESS)". |
| CVE-2008-0599 | Chain: Language interpreter calculates wrong buffer size (CWE-131) by using "size = ptr ? X : Y" instead of "size = (ptr ? X : Y)" expression. |
| CVE-2001-1155 | Chain: product does not properly check the result of a reverse DNS lookup because of operator precedence (CWE-783), allowing bypass of DNS-based access restrictions. |

## Real CVEs with this weakness (sample of 12 of 25)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2024-32896 | Android Pixel Privilege Escalation Vulnerability | high | 7.0 | - | Yes | 2024-06-13 |
| CVE-2017-13322 | - | critical | 10.0 | - | No | 2025-01-17 |
| CVE-2024-20480 | Cisco IOS XE Software SD-Access Fabric Edge Node Denial of Service Vulnerability | high | 8.6 | - | No | 2024-09-25 |
| CVE-2024-20314 | Cisco IOS XE Software SD-Access Fabric Edge Node Denial of Service Vulnerability | high | 8.6 | - | No | 2024-03-27 |
| CVE-2024-31335 | - | high | 8.4 | - | No | 2024-07-09 |
| CVE-2026-7270 | Local privilege escalation via execve() | high | 7.8 | - | No | 2026-04-30 |
| CVE-2023-53763 | Revert "f2fs: fix to do sanity check on extent cache correctly" | high | 7.8 | - | No | 2025-12-08 |
| CVE-2024-44093 | - | high | 7.8 | - | No | 2024-09-13 |
| CVE-2024-34741 | Elevation of privilege in Framework | high | 7.8 | - | No | 2024-08-15 |
| CVE-2024-34726 | - | high | 7.8 | - | No | 2024-07-09 |
| CVE-2024-34723 | Elevation of privilege in Framework | high | 7.8 | - | No | 2024-07-09 |
| CVE-2024-34720 | Elevation of privilege in Framework | high | 7.8 | - | No | 2024-07-09 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-670](https://radicalnotion.ai/cwe/cwe-670) | Always-Incorrect Control Flow Implementation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Use parentheses for precedence of operation | EXP00-C | Exact |
| SEI CERT Perl Coding Standard | Do not mix the early-precedence logical operators with late-precedence logical operators | EXP04-PL | CWE More Abstract |
| OpenSSF Secure Coding Guide for Python | Ensure Correct Operator Precedence | pyscg-0042 | - |

## Frequently asked questions

### What is CWE-783?

The product uses an expression in which operator precedence causes incorrect logic to be used.

### What CVEs are caused by CWE-783?

25 recorded CVEs are attributed to CWE-783, including CVE-2024-32896, CVE-2017-13322 and CVE-2024-20480. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-783?

Regularly wrap sub-expressions in parentheses, especially in security-critical code.

### How is CWE-783 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-783?

Exploiting CWE-783 can lead to: Varies by Context, Unexpected State.

### Is CWE-783 actively exploited?

Yes. 1 CWE-783 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 25 recorded CVEs.

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

---

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