---
title: "CWE-1041: Use of Redundant Code"
url: https://radicalnotion.ai/cwe/cwe-1041
type: cwe
description: "The product has multiple functions, methods, procedures, macros, etc. that contain the same code, i.e., the code has been copied or duplicated."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1041: Use of Redundant Code

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

The product has multiple functions, methods, procedures, macros, etc. that contain the same code, i.e., the code has been copied or duplicated.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Reduce Maintainability | This issue makes it more difficult to maintain the product, which indirectly affects security by making it more difficult or time-consuming to find and/or fix vulnerabilities. For example, if there are two copies of the same code, the programmer might fix a weakness in one copy while forgetting to fix the same weakness in another copy. |

## Potential mitigations

### Implementation (Refactoring)

Merge common functionality into a single function and then call that function from across the entire code base.

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

## Demonstrative examples

### Example 1

In the following Java example the code performs some complex math when specific test conditions are met. The math is the same in each case and the equations are repeated within the code. Unfortunately if a future change needs to be made then that change needs to be made in all locations. This opens the door to mistakes being made and the changes not being made in the same way in each instance.

Bad code:

```java
public class Main {
    public static void main(String[] args) {
        double s = 10.0;
        double r = 1.0;
        double pi = 3.14159;
        double surface_area;

        if(r > 0.0) {
            // complex math equations
            surface_area = pi * r * s + pi * Math.pow(r, 2);

        }

        if(r > 1.0) {
            // a complex set of math
            surface_area = pi * r * s + pi * Math.pow(r, 2);

        }

    }

}
```

Good code:

```java
public class Main {
    private double ComplexMath(double r, double s) {
        //complex math equations
        double pi = Math.PI;
        double surface_area = pi * r * s + pi * Math.pow(r, 2);
        return surface_area;

    }

    public static void main(String[] args) {
        double s = 10.0;
        double r = 1.0;
        double surface_area;

        if(r > 0.0) {
            surface_area = ComplexMath(r, s);

        }

        if(r > 1.0) {
            surface_area = ComplexMath(r, s);

        }

    }

}
```

It is recommended to place the complex math into its own function and then call that function whenever necessary.

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-710](https://radicalnotion.ai/cwe/cwe-710) | Improper Adherence to Coding Standards |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| OMG ASCMM | - | ASCMM-MNT-19 | - |

## Frequently asked questions

### What is CWE-1041?

The product has multiple functions, methods, procedures, macros, etc. that contain the same code, i.e., the code has been copied or duplicated.

### How do you prevent CWE-1041?

Merge common functionality into a single function and then call that function from across the entire code base.

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

Exploiting CWE-1041 can lead to: Reduce Maintainability.

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

---

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