Possible copy-paste error
A section of code is duplicated in other places with exactly one minor change
Since R2023a
Description
This defect occurs when a block of code is duplicated in multiple places with exactly one minor change.
The defect checker does not flag certain blocks as duplicates. For instance, this defect is not reported for blocks that are smaller than 6 lines. See also Duplicate Code Detection in Polyspace Bug Finder.
Risk
Sections of code that are exact duplicates apart from one minor change might indicate a programming error. You might have duplicated a section of code and later updated one of the duplicates but forgot to update the other.
Duplicated code also require unnecessary additional maintenance. See also
Almost
duplicated code
and Duplicated
code
.
Fix
See if the one minor change between the two duplicated blocks is the result of a programming error. Fix the error.
In the long run, try to refactor the sections of code to reduce the duplication. For instance, identify parts of the code blocks that are duplicates of each other and refactor them into a dedicated function. You can then replace the duplicated code with calls to the dedicated function.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
COPY_PASTE_ERROR |
Impact: Low |
Version History
Introduced in R2023aSee Also
Find defects (-checkers)
| Partially duplicated code
| Duplicated code
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Duplicate Code Detection in Polyspace Bug Finder
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)