PVS-Studio and static code analysis technique

Andrey Karpov
Andrey KarpovDevRel en PVS-Studio
PVS-Studio 
and static code analysis technique 
www.viva64.com
What is «static code analysis»? 
• It is a technique that allows, at the same time with unit-tests, dynamic code 
analysis, code review and others, to increase code quality, increase its 
reliability and decrease the development time. 
• It should be noted that static code analysis is not a universal panacea and is 
maximally effective in conjunction with other methods of code testing.
Who needs static code analysis? 
• Any medium-sized and large software development company – to increase 
code reliability and decrease its price, 
• Any small company and individual developers – in a lesser extent – to drink 
coffee instead of searching and fixing annoying bugs, 
• Anyone, who supports any old code, 
• Specialists for specific tasks (for instance, Sparce code analyzer for Linux 
kernel hackers).
Static code analysis advantages 
• Allows to find bugs on early stages (the earlier the bug was spotted, the 
cheaper it is to be fixed), 
• High analysis speed, 
• Does not require to run the application, only an access to source code and 
(not always) – to preprocessed files, 
• Allows to locate bugs in code that is rarely executed (exception handlers, for 
instance).
Static code analysis disadvantages 
• Possibility of false positive alarm on correct code, 
• Correct positive alarms on old code, which works correctly and which should 
better not be bothered, may be nauseous. 
• Comparatively small class of bugs detected due to the exponential difficulty 
of “honest” bug search. 
• Does not detects logical errors (this is a drawback of almost all automatic 
testing tools in contrast to code review and manually written unit tests).
PVS-Studio 
• One of static code analysis tools for C and C++ languages (including C++CX, 
C++0x and C++11), 
• Developers – ООО «Program Verification Systems». 
• Site: http://www.viva64.com/ 
• From so on, main advantages of this tool will be listed.
PVS-Studio: ease of use 
• Allows integration into Microsoft Visual Studio (except for Express version – 
it lacks extension mechanisms), 
• Includes PVS-Studio Standalone that does not require IDE at all, 
• Works quickly and “out-of-the-box”, does not require dedicated database 
servers and personnel training. 
• Can be integrated into the build system, 
• Fully-functional trial version.
PVS-Studio: features 
• Incremental analysis allows to find bugs in new code after every build, 
• Message suppression allows to concentrate on a newly written code by 
hiding all the warning messages on the old code (of course, they can be 
reviewed later), 
• Special feature – search for bugs that shows up on porting 32-bit application 
into 64-bit ones.
PVS-Studio: additional features 
• Quick tech support, 
• Users may ask for a features in a future releases. Our tool is expanding, and 
we try to take into account every request, 
• All errors are properly documented and there are a lot of examples (small 
fraction of them will be listed on the next slides).
Examples of errors found in 
real-life applications 
Error #1 
while (node != NULL) { 
if ((node->hashCode == code) && 
(node->entry.key == key)) { 
return true; 
} 
node = node->next; 
} while (node != NULL); 
It seems like do / while cycles was mixed 
up in a weird way here. Of course, 
second ‘while’ operator should never 
become an endless cycle, but is there 
actually ‘while’ and not ‘do’ cycle 
required?
Examples of errors found in 
real-life applications 
Error #2 
int main(int argc, char** argv) { 
.... 
if (getIsInteractiveMode()) 
//p->writePepSHTML(); 
//p->printResult(); 
// regression test? 
if (testType!=NO_TEST) { 
.... 
} 
} 
Even comments can sometimes harm the 
program, especially in the wrong place. In 
this piece of code second ‘if’ operator will 
only be evaluated if condition in first ‘if’ is 
true, but code formatting says that the 
opposite was intended. By the way, this 
error was found in unit tests.
Examples of errors found in 
real-life applications 
Error #3 
HRESULT 
SHEOW_LoadOpenWithItems(....) 
{ 
.... 
if (_ILIsDesktop(pidl) || _ILIsMyDocuments(pidl) 
|| _ILIsControlPanel(pidl) || _ILIsNetHood(pidl) 
|| _ILIsBitBucket(pidl) || _ILIsDrive(pidl) 
|| _ILIsCPanelStruct(pidl) || _ILIsFolder(pidl) 
|| _ILIsControlPanel(pidl)) 
{ 
TRACE("pidl is a foldern"); 
SHFree((void*)pidl); 
return E_FAIL; 
} 
.... 
} 
For everyone who thinks that every 
problem that was found by static code 
analyzer can also be found by code 
review. Good luck in figuring out what’s 
wrong here. And don’t forget that real 
code is much, much bigger than this 
fragment.
Examples of errors found in 
real-life applications 
Error #3 
HRESULT 
SHEOW_LoadOpenWithItems(....) 
{ 
.... 
if (_ILIsDesktop(pidl) || _ILIsMyDocuments(pidl) 
|| _ILIsControlPanel(pidl) || _ILIsNetHood(pidl) 
|| _ILIsBitBucket(pidl) || _ILIsDrive(pidl) 
|| _ILIsCPanelStruct(pidl) || _ILIsFolder(pidl) 
|| _ILIsControlPanel(pidl)) 
{ 
TRACE("pidl is a foldern"); 
SHFree((void*)pidl); 
return E_FAIL; 
} 
.... 
} 
Here it is. A repeated fragment in a 
logical expression. At least one of this 
repeated sentences is redundant. More 
likely scenario: one of this sentences is 
incorrect, and programmer should have 
meant something else.
Examples of errors found in 
real-life applications 
Error #4 
Style & w1Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD1_INDEX); 
styleUpdate(w1Style, _pFgColour[0], _pBgColour[0], 
IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD1_FONTSIZE_COMBO, 
IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, 
IDC_KEYWORD1_UNDERLINE_CHECK); 
Style & w2Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD2_INDEX); 
styleUpdate(w2Style, _pFgColour[1], _pBgColour[1], 
IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, 
IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, 
IDC_KEYWORD2_UNDERLINE_CHECK); 
Style & w3Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD3_INDEX); 
styleUpdate(w3Style, _pFgColour[2], _pBgColour[2], 
IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, 
IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_BOLD_CHECK, 
IDC_KEYWORD3_UNDERLINE_CHECK); 
Style & w4Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD4_INDEX); 
styleUpdate(w4Style, _pFgColour[3], _pBgColour[3], 
IDC_KEYWORD4_FONT_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO, 
IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, 
IDC_KEYWORD4_UNDERLINE_CHECK); 
Still not impressed? Well, here comes 
another example.
Examples of errors found in 
real-life applications 
Error #4 
Nice example of code produced by 
copy-paste technique featuring 
programmer who forgot to fix one 
word. This error is definitely hard to 
detect using only code review. 
However, if you enjoyed searching for 
errors, we have a quiz for you. 
Style & w1Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD1_INDEX); 
styleUpdate(w1Style, _pFgColour[0], _pBgColour[0], 
IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD1_FONTSIZE_COMBO, 
IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, 
IDC_KEYWORD1_UNDERLINE_CHECK); 
Style & w2Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD2_INDEX); 
styleUpdate(w2Style, _pFgColour[1], _pBgColour[1], 
IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, 
IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, 
IDC_KEYWORD2_UNDERLINE_CHECK); 
Style & w3Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD3_INDEX); 
styleUpdate(w3Style, _pFgColour[2], _pBgColour[2], 
IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, 
IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_BOLD_CHECK, 
IDC_KEYWORD3_UNDERLINE_CHECK); 
Style & w4Style = 
_pUserLang->_styleArray.getStyler(STYLE_WORD4_INDEX); 
styleUpdate(w4Style, _pFgColour[3], _pBgColour[3], 
IDC_KEYWORD4_FONT_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO, 
IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, 
IDC_KEYWORD4_UNDERLINE_CHECK);
Examples of errors found in 
real-life applications 
Error #5 
void ListJob::doStart() 
{ 
Q_D( ListJob ); 
switch ( d->option ) { 
break; 
case IncludeUnsubscribed: 
d->command = "LIST"; 
break; 
case IncludeFolderRoleFlags: 
d->command = "XLIST"; 
break; 
case NoOption: 
default: 
d->command = "LSUB"; 
} 
.... 
} 
One single ‘break’ in unusual place may 
alter the whole ‘switch’ statement 
behavior. Or maybe it was intentional, 
wasn’t it?
Conclusion 
• All the errors listed in this presentation was found in open-source projects. It 
proves that even professional programmers tend to make errors. 
• It is worth to remind that it is better to use the whole bunch of tools, not only static 
code analysis or only unit tests, and to give enough attention to refactoring and 
code quality. We are almost certain that this will pay for itself. Analyzer may find a 
misprint, but would never find a wrong algorithm! Unit tests may contain errors 
too, and human attention would hardly find a misprint in heaps of duplicate code. 
• Good luck with development!
Additional links: 
• PVS-Studio: http://www.viva64.com/en/pvs-studio/ 
• Updatable List of Open-Source Projects Checked with PVS-Studio: 
http://www.viva64.com/en/a/0084/ 
• Blog: http://www.viva64.com/en/b/ 
• Twitter: https://twitter.com/Code_Analysis
1 de 18

Recomendados

PVS-Studio features overview (2020) por
PVS-Studio features overview (2020)PVS-Studio features overview (2020)
PVS-Studio features overview (2020)Andrey Karpov
37 vistas32 diapositivas
Static code analysis por
Static code analysisStatic code analysis
Static code analysisRune Sundling
3.5K vistas38 diapositivas
Static Code Analysis por
Static Code AnalysisStatic Code Analysis
Static Code AnalysisGeneva, Switzerland
3.8K vistas25 diapositivas
Top 10 static code analysis tool por
Top 10 static code analysis toolTop 10 static code analysis tool
Top 10 static code analysis toolscmGalaxy Inc
1K vistas11 diapositivas
Pragmatic Code Coverage por
Pragmatic Code CoveragePragmatic Code Coverage
Pragmatic Code CoverageAlexandre (Shura) Iline
1.6K vistas65 diapositivas
PVS-Studio advertisement - static analysis of C/C++ code por
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codeAndrey Karpov
1.2K vistas46 diapositivas

Más contenido relacionado

La actualidad más candente

Java Code Quality Tools por
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality ToolsOrest Ivasiv
20.6K vistas9 diapositivas
Server Side Template Injection by Mandeep Jadon por
Server Side Template Injection by Mandeep JadonServer Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep JadonMandeep Jadon
441 vistas22 diapositivas
Parasoft fda software compliance part2 por
Parasoft fda software compliance   part2Parasoft fda software compliance   part2
Parasoft fda software compliance part2Engineering Software Lab
716 vistas15 diapositivas
Sonar Tool - JAVA code analysis por
Sonar Tool - JAVA code analysisSonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysisPrashant Gupta
2.2K vistas12 diapositivas
PVS-Studio is ready to improve the code of Tizen operating system por
PVS-Studio is ready to improve the code of Tizen operating systemPVS-Studio is ready to improve the code of Tizen operating system
PVS-Studio is ready to improve the code of Tizen operating systemAndrey Karpov
2.8K vistas77 diapositivas
Effective code reviews por
Effective code reviewsEffective code reviews
Effective code reviewsSebastian Marek
2.7K vistas41 diapositivas

La actualidad más candente(20)

Java Code Quality Tools por Orest Ivasiv
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
Orest Ivasiv20.6K vistas
Server Side Template Injection by Mandeep Jadon por Mandeep Jadon
Server Side Template Injection by Mandeep JadonServer Side Template Injection by Mandeep Jadon
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon441 vistas
Sonar Tool - JAVA code analysis por Prashant Gupta
Sonar Tool - JAVA code analysisSonar Tool - JAVA code analysis
Sonar Tool - JAVA code analysis
Prashant Gupta2.2K vistas
PVS-Studio is ready to improve the code of Tizen operating system por Andrey Karpov
PVS-Studio is ready to improve the code of Tizen operating systemPVS-Studio is ready to improve the code of Tizen operating system
PVS-Studio is ready to improve the code of Tizen operating system
Andrey Karpov2.8K vistas
PVS-Studio for Visual C++ por Andrey Karpov
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++
Andrey Karpov383 vistas
Continuous Integration: Live Static Analysis with Puma Scan por Cypress Data Defense
Continuous Integration: Live Static Analysis with Puma ScanContinuous Integration: Live Static Analysis with Puma Scan
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense1.4K vistas
150412 38 beamer methods of binary analysis por Raghu Palakodety
150412 38 beamer methods of  binary analysis150412 38 beamer methods of  binary analysis
150412 38 beamer methods of binary analysis
Raghu Palakodety709 vistas
Static Code Analysis for Projects, Built on Unreal Engine por Andrey Karpov
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov529 vistas
Code Review por rantav
Code ReviewCode Review
Code Review
rantav6.6K vistas
Code review for secure web applications por silviad74
Code review for secure web applicationsCode review for secure web applications
Code review for secure web applications
silviad742.2K vistas
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자 por Taeyeop Kim
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim1.3K vistas
Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev por Yandex
 Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev
Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev
Yandex353 vistas
Software Engineering - RS3 por Atakan Aral
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
Atakan Aral558 vistas
PVS-Studio static analyzer: advanced features por Andrey Karpov
PVS-Studio static analyzer: advanced featuresPVS-Studio static analyzer: advanced features
PVS-Studio static analyzer: advanced features
Andrey Karpov579 vistas
Crowd debugging (FSE 2015) por Sung Kim
Crowd debugging (FSE 2015)Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)
Sung Kim1.9K vistas
Java Code Review Checklist por Mahesh Chopker
Java Code Review ChecklistJava Code Review Checklist
Java Code Review Checklist
Mahesh Chopker7.9K vistas
Code Review por Tu Hoang
Code ReviewCode Review
Code Review
Tu Hoang1.2K vistas

Destacado

Static code analysis por
Static code analysisStatic code analysis
Static code analysismashaathukorala
590 vistas32 diapositivas
Verification at scale: Fitting static code analysis into continuous integration por
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationRogue Wave Software
505 vistas24 diapositivas
Learning from other's mistakes: Data-driven code analysis por
Learning from other's mistakes: Data-driven code analysisLearning from other's mistakes: Data-driven code analysis
Learning from other's mistakes: Data-driven code analysisAndreas Dewes
2.5K vistas30 diapositivas
Static Code Analysis and AutoLint por
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLintLeander Hasty
2.5K vistas16 diapositivas
Static Analysis Techniques For Testing Application Security - Houston Tech Fest por
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestDenim Group
4K vistas49 diapositivas
Quick tour to front end unit testing using jasmine por
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
3K vistas31 diapositivas

Destacado(10)

Verification at scale: Fitting static code analysis into continuous integration por Rogue Wave Software
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integration
Learning from other's mistakes: Data-driven code analysis por Andreas Dewes
Learning from other's mistakes: Data-driven code analysisLearning from other's mistakes: Data-driven code analysis
Learning from other's mistakes: Data-driven code analysis
Andreas Dewes2.5K vistas
Static Code Analysis and AutoLint por Leander Hasty
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLint
Leander Hasty2.5K vistas
Static Analysis Techniques For Testing Application Security - Houston Tech Fest por Denim Group
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Denim Group4K vistas
Quick tour to front end unit testing using jasmine por Gil Fink
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink3K vistas
Static Code Analysis por Annyce Davis
Static Code AnalysisStatic Code Analysis
Static Code Analysis
Annyce Davis3.4K vistas
Unit Testing Concepts and Best Practices por Derek Smith
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith31.8K vistas
UNIT TESTING PPT por suhasreddy1
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy155.4K vistas

Similar a PVS-Studio and static code analysis technique

Code quality par Simone Civetta por
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone CivettaCocoaHeads France
4.8K vistas83 diapositivas
PVS-Studio advertisement - static analysis of C/C++ code por
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio
549 vistas70 diapositivas
PVS-Studio: analyzing ReactOS's code por
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio
425 vistas11 diapositivas
Measuring Your Code por
Measuring Your CodeMeasuring Your Code
Measuring Your CodeNate Abele
10 vistas60 diapositivas
Measuring Your Code 2.0 por
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0Nate Abele
1.4K vistas60 diapositivas
Improving Code Quality Through Effective Review Process por
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
721 vistas32 diapositivas

Similar a PVS-Studio and static code analysis technique(20)

PVS-Studio advertisement - static analysis of C/C++ code por PVS-Studio
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio549 vistas
PVS-Studio: analyzing ReactOS's code por PVS-Studio
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
PVS-Studio425 vistas
Measuring Your Code por Nate Abele
Measuring Your CodeMeasuring Your Code
Measuring Your Code
Nate Abele10 vistas
Measuring Your Code 2.0 por Nate Abele
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
Nate Abele1.4K vistas
Improving Code Quality Through Effective Review Process por Dr. Syed Hassan Amin
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Checking the Qt 5 Framework por Andrey Karpov
Checking the Qt 5 FrameworkChecking the Qt 5 Framework
Checking the Qt 5 Framework
Andrey Karpov460 vistas
We continue checking Microsoft projects: analysis of PowerShell por PVS-Studio
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
PVS-Studio172 vistas
The operation principles of PVS-Studio static code analyzer por Andrey Karpov
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
Andrey Karpov624 vistas
Chelberg ptcuser 2010 por Clay Helberg
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
Clay Helberg574 vistas
Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo... por Zhen Huang
Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo...Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo...
Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo...
Zhen Huang77 vistas
how-to-bypass-AM-PPL por nitinscribd
how-to-bypass-AM-PPLhow-to-bypass-AM-PPL
how-to-bypass-AM-PPL
nitinscribd304 vistas
Analysis of Godot Engine's Source Code por PVS-Studio
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source Code
PVS-Studio126 vistas
What's the Difference Between Static Analysis and Compiler Warnings? por Andrey Karpov
What's the Difference Between Static Analysis and Compiler Warnings?What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?
Andrey Karpov337 vistas
Looking for Bugs in MonoDevelop por PVS-Studio
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelop
PVS-Studio270 vistas

Más de Andrey Karpov

60 антипаттернов для С++ программиста por
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программистаAndrey Karpov
12 vistas80 diapositivas
60 terrible tips for a C++ developer por
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developerAndrey Karpov
25 vistas85 diapositivas
PVS-Studio in 2021 - Error Examples por
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
106 vistas30 diapositivas
PVS-Studio in 2021 - Feature Overview por
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewAndrey Karpov
122 vistas28 diapositivas
PVS-Studio в 2021 - Примеры ошибок por
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокAndrey Karpov
56 vistas30 diapositivas
PVS-Studio в 2021 por
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021Andrey Karpov
95 vistas28 diapositivas

Más de Andrey Karpov(20)

60 антипаттернов для С++ программиста por Andrey Karpov
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
Andrey Karpov12 vistas
60 terrible tips for a C++ developer por Andrey Karpov
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
Andrey Karpov25 vistas
PVS-Studio in 2021 - Error Examples por Andrey Karpov
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
Andrey Karpov106 vistas
PVS-Studio in 2021 - Feature Overview por Andrey Karpov
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
Andrey Karpov122 vistas
PVS-Studio в 2021 - Примеры ошибок por Andrey Karpov
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
Andrey Karpov56 vistas
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng... por Andrey Karpov
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Andrey Karpov69 vistas
Best Bugs from Games: Fellow Programmers' Mistakes por Andrey Karpov
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
Andrey Karpov530 vistas
Does static analysis need machine learning? por Andrey Karpov
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
Andrey Karpov142 vistas
Typical errors in code on the example of C++, C#, and Java por Andrey Karpov
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and Java
Andrey Karpov761 vistas
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4) por Andrey Karpov
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
Andrey Karpov121 vistas
Game Engine Code Quality: Is Everything Really That Bad? por Andrey Karpov
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?
Andrey Karpov106 vistas
C++ Code as Seen by a Hypercritical Reviewer por Andrey Karpov
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov143 vistas
The Use of Static Code Analysis When Teaching or Developing Open-Source Software por Andrey Karpov
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
Andrey Karpov50 vistas
Static code analysis: what? how? why? por Andrey Karpov
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
Andrey Karpov38 vistas
Zero, one, two, Freddy's coming for you por Andrey Karpov
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
Andrey Karpov87 vistas
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps por Andrey Karpov
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOpsPVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
Andrey Karpov51 vistas
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab... por Andrey Karpov
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
Andrey Karpov52 vistas
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ... por Andrey Karpov
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Andrey Karpov58 vistas

Último

Short_Story_PPT.pdf por
Short_Story_PPT.pdfShort_Story_PPT.pdf
Short_Story_PPT.pdfutkarshsatishkumarsh
6 vistas16 diapositivas
Bootstrapping vs Venture Capital.pptx por
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptxZeljko Svedic
12 vistas17 diapositivas
Unleash The Monkeys por
Unleash The MonkeysUnleash The Monkeys
Unleash The MonkeysJacob Duijzer
8 vistas28 diapositivas
Ports-and-Adapters Architecture for Embedded HMI por
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
21 vistas19 diapositivas
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action por
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionMárton Kodok
11 vistas55 diapositivas
MS PowerPoint.pptx por
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptxLitty Sylus
5 vistas14 diapositivas

Último(20)

Bootstrapping vs Venture Capital.pptx por Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic12 vistas
Ports-and-Adapters Architecture for Embedded HMI por Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert21 vistas
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action por Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok11 vistas
Generic or specific? Making sensible software design decisions por Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
tecnologia18.docx por nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 vistas
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller41 vistas
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... por Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke35 vistas
Sprint 226 por ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ8 vistas
Dapr Unleashed: Accelerating Microservice Development por Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski12 vistas
Top-5-production-devconMunich-2023.pptx por Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app8 vistas
Quality Engineer: A Day in the Life por John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 vistas
The Era of Large Language Models.pptx por AbdulVahedShaik
The Era of Large Language Models.pptxThe Era of Large Language Models.pptx
The Era of Large Language Models.pptx
AbdulVahedShaik7 vistas
Fleet Management Software in India por Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable12 vistas

PVS-Studio and static code analysis technique

  • 1. PVS-Studio and static code analysis technique www.viva64.com
  • 2. What is «static code analysis»? • It is a technique that allows, at the same time with unit-tests, dynamic code analysis, code review and others, to increase code quality, increase its reliability and decrease the development time. • It should be noted that static code analysis is not a universal panacea and is maximally effective in conjunction with other methods of code testing.
  • 3. Who needs static code analysis? • Any medium-sized and large software development company – to increase code reliability and decrease its price, • Any small company and individual developers – in a lesser extent – to drink coffee instead of searching and fixing annoying bugs, • Anyone, who supports any old code, • Specialists for specific tasks (for instance, Sparce code analyzer for Linux kernel hackers).
  • 4. Static code analysis advantages • Allows to find bugs on early stages (the earlier the bug was spotted, the cheaper it is to be fixed), • High analysis speed, • Does not require to run the application, only an access to source code and (not always) – to preprocessed files, • Allows to locate bugs in code that is rarely executed (exception handlers, for instance).
  • 5. Static code analysis disadvantages • Possibility of false positive alarm on correct code, • Correct positive alarms on old code, which works correctly and which should better not be bothered, may be nauseous. • Comparatively small class of bugs detected due to the exponential difficulty of “honest” bug search. • Does not detects logical errors (this is a drawback of almost all automatic testing tools in contrast to code review and manually written unit tests).
  • 6. PVS-Studio • One of static code analysis tools for C and C++ languages (including C++CX, C++0x and C++11), • Developers – ООО «Program Verification Systems». • Site: http://www.viva64.com/ • From so on, main advantages of this tool will be listed.
  • 7. PVS-Studio: ease of use • Allows integration into Microsoft Visual Studio (except for Express version – it lacks extension mechanisms), • Includes PVS-Studio Standalone that does not require IDE at all, • Works quickly and “out-of-the-box”, does not require dedicated database servers and personnel training. • Can be integrated into the build system, • Fully-functional trial version.
  • 8. PVS-Studio: features • Incremental analysis allows to find bugs in new code after every build, • Message suppression allows to concentrate on a newly written code by hiding all the warning messages on the old code (of course, they can be reviewed later), • Special feature – search for bugs that shows up on porting 32-bit application into 64-bit ones.
  • 9. PVS-Studio: additional features • Quick tech support, • Users may ask for a features in a future releases. Our tool is expanding, and we try to take into account every request, • All errors are properly documented and there are a lot of examples (small fraction of them will be listed on the next slides).
  • 10. Examples of errors found in real-life applications Error #1 while (node != NULL) { if ((node->hashCode == code) && (node->entry.key == key)) { return true; } node = node->next; } while (node != NULL); It seems like do / while cycles was mixed up in a weird way here. Of course, second ‘while’ operator should never become an endless cycle, but is there actually ‘while’ and not ‘do’ cycle required?
  • 11. Examples of errors found in real-life applications Error #2 int main(int argc, char** argv) { .... if (getIsInteractiveMode()) //p->writePepSHTML(); //p->printResult(); // regression test? if (testType!=NO_TEST) { .... } } Even comments can sometimes harm the program, especially in the wrong place. In this piece of code second ‘if’ operator will only be evaluated if condition in first ‘if’ is true, but code formatting says that the opposite was intended. By the way, this error was found in unit tests.
  • 12. Examples of errors found in real-life applications Error #3 HRESULT SHEOW_LoadOpenWithItems(....) { .... if (_ILIsDesktop(pidl) || _ILIsMyDocuments(pidl) || _ILIsControlPanel(pidl) || _ILIsNetHood(pidl) || _ILIsBitBucket(pidl) || _ILIsDrive(pidl) || _ILIsCPanelStruct(pidl) || _ILIsFolder(pidl) || _ILIsControlPanel(pidl)) { TRACE("pidl is a foldern"); SHFree((void*)pidl); return E_FAIL; } .... } For everyone who thinks that every problem that was found by static code analyzer can also be found by code review. Good luck in figuring out what’s wrong here. And don’t forget that real code is much, much bigger than this fragment.
  • 13. Examples of errors found in real-life applications Error #3 HRESULT SHEOW_LoadOpenWithItems(....) { .... if (_ILIsDesktop(pidl) || _ILIsMyDocuments(pidl) || _ILIsControlPanel(pidl) || _ILIsNetHood(pidl) || _ILIsBitBucket(pidl) || _ILIsDrive(pidl) || _ILIsCPanelStruct(pidl) || _ILIsFolder(pidl) || _ILIsControlPanel(pidl)) { TRACE("pidl is a foldern"); SHFree((void*)pidl); return E_FAIL; } .... } Here it is. A repeated fragment in a logical expression. At least one of this repeated sentences is redundant. More likely scenario: one of this sentences is incorrect, and programmer should have meant something else.
  • 14. Examples of errors found in real-life applications Error #4 Style & w1Style = _pUserLang->_styleArray.getStyler(STYLE_WORD1_INDEX); styleUpdate(w1Style, _pFgColour[0], _pBgColour[0], IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD1_FONTSIZE_COMBO, IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, IDC_KEYWORD1_UNDERLINE_CHECK); Style & w2Style = _pUserLang->_styleArray.getStyler(STYLE_WORD2_INDEX); styleUpdate(w2Style, _pFgColour[1], _pBgColour[1], IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, IDC_KEYWORD2_UNDERLINE_CHECK); Style & w3Style = _pUserLang->_styleArray.getStyler(STYLE_WORD3_INDEX); styleUpdate(w3Style, _pFgColour[2], _pBgColour[2], IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_UNDERLINE_CHECK); Style & w4Style = _pUserLang->_styleArray.getStyler(STYLE_WORD4_INDEX); styleUpdate(w4Style, _pFgColour[3], _pBgColour[3], IDC_KEYWORD4_FONT_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO, IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, IDC_KEYWORD4_UNDERLINE_CHECK); Still not impressed? Well, here comes another example.
  • 15. Examples of errors found in real-life applications Error #4 Nice example of code produced by copy-paste technique featuring programmer who forgot to fix one word. This error is definitely hard to detect using only code review. However, if you enjoyed searching for errors, we have a quiz for you. Style & w1Style = _pUserLang->_styleArray.getStyler(STYLE_WORD1_INDEX); styleUpdate(w1Style, _pFgColour[0], _pBgColour[0], IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD1_FONTSIZE_COMBO, IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, IDC_KEYWORD1_UNDERLINE_CHECK); Style & w2Style = _pUserLang->_styleArray.getStyler(STYLE_WORD2_INDEX); styleUpdate(w2Style, _pFgColour[1], _pBgColour[1], IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, IDC_KEYWORD2_UNDERLINE_CHECK); Style & w3Style = _pUserLang->_styleArray.getStyler(STYLE_WORD3_INDEX); styleUpdate(w3Style, _pFgColour[2], _pBgColour[2], IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_UNDERLINE_CHECK); Style & w4Style = _pUserLang->_styleArray.getStyler(STYLE_WORD4_INDEX); styleUpdate(w4Style, _pFgColour[3], _pBgColour[3], IDC_KEYWORD4_FONT_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO, IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, IDC_KEYWORD4_UNDERLINE_CHECK);
  • 16. Examples of errors found in real-life applications Error #5 void ListJob::doStart() { Q_D( ListJob ); switch ( d->option ) { break; case IncludeUnsubscribed: d->command = "LIST"; break; case IncludeFolderRoleFlags: d->command = "XLIST"; break; case NoOption: default: d->command = "LSUB"; } .... } One single ‘break’ in unusual place may alter the whole ‘switch’ statement behavior. Or maybe it was intentional, wasn’t it?
  • 17. Conclusion • All the errors listed in this presentation was found in open-source projects. It proves that even professional programmers tend to make errors. • It is worth to remind that it is better to use the whole bunch of tools, not only static code analysis or only unit tests, and to give enough attention to refactoring and code quality. We are almost certain that this will pay for itself. Analyzer may find a misprint, but would never find a wrong algorithm! Unit tests may contain errors too, and human attention would hardly find a misprint in heaps of duplicate code. • Good luck with development!
  • 18. Additional links: • PVS-Studio: http://www.viva64.com/en/pvs-studio/ • Updatable List of Open-Source Projects Checked with PVS-Studio: http://www.viva64.com/en/a/0084/ • Blog: http://www.viva64.com/en/b/ • Twitter: https://twitter.com/Code_Analysis