Professional Documents
Culture Documents
To Get A Trial Key Fill Out The Form Below: Team License (Standard Version) Enterprise License (Extended Version)
To Get A Trial Key Fill Out The Form Below: Team License (Standard Version) Enterprise License (Extended Version)
Submit
New License
License Renewal
I am a reseller
--Select currency--
Submit
Didn't get our email?
Please attach your files here. The total size limit is 20MB. The .exe and .i files are not
supported.
Submit
To get the licence for your open-source project, please fill out this form
To get the licence for your open-source project, please fill out this form
Get a license
Windows
Linux
macOS
Submit form
Download
Analyzer
Documentation
Prices
For clients
Publications
About us
Home
>
Posts
>
Terminology
>
Copy-Paste programming
Aug 14 2012
Copy-Paste programming
It's best to catch copy-paste mistakes at the stage of code writing in automatic
mode. For instance, you can use the static analysis methodology. Unlike ordinary
manual review, static analysis is usually completely automated and covers the
whole project code - even those fragments which are executed seldom and where
errors are difficult to detect through dynamic verification methods.
Here are several examples of real errors of the copy-paste pattern in C++ found in
popular open-source projects with the PVS-Studio static analyzer.
The Fennec Media Project project. A slip when handling array items.
fhead[11] = '\0';
fhead[12] = '\0';
fhead[13] = '\0';
fhead[13] = '\0';
The four similar lines must have appeared in the program through copying. Then
the programmer made a mistake when editing indexes which caused zero to be
written into 'fhead[13] ' twice and not be written at all into 'fhead[14] '.
The 'hsh' object is not used. It is the 'hhi' object which is used all the time.
More examples of copy-paste errors (and other issues) detected with the help of
the static analysis methodology can be found here.
References
Wikipedia. Anti-pattern.