SlideShare a Scribd company logo
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
Ad

Recommended

PPTX
PVS-Studio features overview (2020)
Andrey Karpov
 
PPTX
Static code analysis
Rune Sundling
 
PPTX
Static Code Analysis
Geneva, Switzerland
 
PPTX
Top 10 static code analysis tool
scmGalaxy Inc
 
PDF
Pragmatic Code Coverage
Alexandre (Shura) Iline
 
PDF
PVS-Studio advertisement - static analysis of C/C++ code
Andrey Karpov
 
PPTX
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Andrey Karpov
 
PPTX
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
Andrey Karpov
 
PPTX
Java Code Quality Tools
Orest Ivasiv
 
PPTX
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon
 
PDF
Parasoft fda software compliance part2
Engineering Software Lab
 
PPTX
Sonar Tool - JAVA code analysis
Prashant Gupta
 
PPTX
PVS-Studio is ready to improve the code of Tizen operating system
Andrey Karpov
 
PDF
Effective code reviews
Sebastian Marek
 
PDF
PVS-Studio for Visual C++
Andrey Karpov
 
PDF
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense
 
PDF
150412 38 beamer methods of binary analysis
Raghu Palakodety
 
PPTX
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov
 
PPT
Code Review
rantav
 
PPT
Code review for secure web applications
silviad74
 
PPTX
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim
 
PDF
Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev
Yandex
 
PDF
Software Engineering - RS3
AtakanAral
 
PPTX
PVS-Studio static analyzer: advanced features
Andrey Karpov
 
PPT
Crowd debugging (FSE 2015)
Sung Kim
 
PDF
Java Code Review Checklist
Mahesh Chopker
 
ODP
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
PDF
Code Review
Tu Hoang
 
PPTX
Static code analysis
mashaathukorala
 
PPTX
Verification at scale: Fitting static code analysis into continuous integration
Rogue Wave Software
 

More Related Content

What's hot (20)

PPTX
Java Code Quality Tools
Orest Ivasiv
 
PPTX
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon
 
PDF
Parasoft fda software compliance part2
Engineering Software Lab
 
PPTX
Sonar Tool - JAVA code analysis
Prashant Gupta
 
PPTX
PVS-Studio is ready to improve the code of Tizen operating system
Andrey Karpov
 
PDF
Effective code reviews
Sebastian Marek
 
PDF
PVS-Studio for Visual C++
Andrey Karpov
 
PDF
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense
 
PDF
150412 38 beamer methods of binary analysis
Raghu Palakodety
 
PPTX
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov
 
PPT
Code Review
rantav
 
PPT
Code review for secure web applications
silviad74
 
PPTX
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim
 
PDF
Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev
Yandex
 
PDF
Software Engineering - RS3
AtakanAral
 
PPTX
PVS-Studio static analyzer: advanced features
Andrey Karpov
 
PPT
Crowd debugging (FSE 2015)
Sung Kim
 
PDF
Java Code Review Checklist
Mahesh Chopker
 
ODP
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
PDF
Code Review
Tu Hoang
 
Java Code Quality Tools
Orest Ivasiv
 
Server Side Template Injection by Mandeep Jadon
Mandeep Jadon
 
Parasoft fda software compliance part2
Engineering Software Lab
 
Sonar Tool - JAVA code analysis
Prashant Gupta
 
PVS-Studio is ready to improve the code of Tizen operating system
Andrey Karpov
 
Effective code reviews
Sebastian Marek
 
PVS-Studio for Visual C++
Andrey Karpov
 
Continuous Integration: Live Static Analysis with Puma Scan
Cypress Data Defense
 
150412 38 beamer methods of binary analysis
Raghu Palakodety
 
Static Code Analysis for Projects, Built on Unreal Engine
Andrey Karpov
 
Code Review
rantav
 
Code review for secure web applications
silviad74
 
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
Taeyeop Kim
 
Making Your Own Static Analyzer Using Freud DSL. Marat Vyshegorodtsev
Yandex
 
Software Engineering - RS3
AtakanAral
 
PVS-Studio static analyzer: advanced features
Andrey Karpov
 
Crowd debugging (FSE 2015)
Sung Kim
 
Java Code Review Checklist
Mahesh Chopker
 
Introduction to Binary Exploitation
Cysinfo Cyber Security Community
 
Code Review
Tu Hoang
 

Viewers also liked (10)

PPTX
Static code analysis
mashaathukorala
 
PPTX
Verification at scale: Fitting static code analysis into continuous integration
Rogue Wave Software
 
PPTX
Learning from other's mistakes: Data-driven code analysis
Andreas Dewes
 
PPT
Static Code Analysis and AutoLint
Leander Hasty
 
PDF
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Denim Group
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
Static Code Analysis
Annyce Davis
 
PPTX
Anaemia in heart failure
drabhishekbabbu
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PPTX
UNIT TESTING PPT
suhasreddy1
 
Static code analysis
mashaathukorala
 
Verification at scale: Fitting static code analysis into continuous integration
Rogue Wave Software
 
Learning from other's mistakes: Data-driven code analysis
Andreas Dewes
 
Static Code Analysis and AutoLint
Leander Hasty
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Denim Group
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Static Code Analysis
Annyce Davis
 
Anaemia in heart failure
drabhishekbabbu
 
Unit Testing Concepts and Best Practices
Derek Smith
 
UNIT TESTING PPT
suhasreddy1
 
Ad

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

PDF
Code quality par Simone Civetta
CocoaHeads France
 
PDF
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio
 
PDF
PVS-Studio: analyzing ReactOS's code
PVS-Studio
 
PDF
Measuring Your Code
Nate Abele
 
PDF
Measuring Your Code 2.0
Nate Abele
 
PPTX
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
PPT
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Engineering Software Lab
 
PDF
Checking the Qt 5 Framework
Andrey Karpov
 
PDF
We continue checking Microsoft projects: analysis of PowerShell
PVS-Studio
 
PPTX
The operation principles of PVS-Studio static code analyzer
Andrey Karpov
 
PPT
Chelberg ptcuser 2010
Clay Helberg
 
PDF
Python and test
Micron Technology
 
PPTX
Price of an Error
Andrey Karpov
 
PPTX
Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo...
Zhen Huang
 
PDF
Wtf per lineofcode
David Gómez García
 
PDF
how-to-bypass-AM-PPL
nitinscribd
 
PDF
Analysis of Godot Engine's Source Code
PVS-Studio
 
ODP
The Art Of Debugging
svilen.ivanov
 
PDF
What's the Difference Between Static Analysis and Compiler Warnings?
Andrey Karpov
 
PDF
Looking for Bugs in MonoDevelop
PVS-Studio
 
Code quality par Simone Civetta
CocoaHeads France
 
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio
 
Measuring Your Code
Nate Abele
 
Measuring Your Code 2.0
Nate Abele
 
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Engineering Software Lab
 
Checking the Qt 5 Framework
Andrey Karpov
 
We continue checking Microsoft projects: analysis of PowerShell
PVS-Studio
 
The operation principles of PVS-Studio static code analyzer
Andrey Karpov
 
Chelberg ptcuser 2010
Clay Helberg
 
Python and test
Micron Technology
 
Price of an Error
Andrey Karpov
 
Talos: Neutralizing Vulnerabilities with Security Workarounds for Rapid Respo...
Zhen Huang
 
Wtf per lineofcode
David Gómez García
 
how-to-bypass-AM-PPL
nitinscribd
 
Analysis of Godot Engine's Source Code
PVS-Studio
 
The Art Of Debugging
svilen.ivanov
 
What's the Difference Between Static Analysis and Compiler Warnings?
Andrey Karpov
 
Looking for Bugs in MonoDevelop
PVS-Studio
 
Ad

More from Andrey Karpov (20)

PDF
60 антипаттернов для С++ программиста
Andrey Karpov
 
PDF
60 terrible tips for a C++ developer
Andrey Karpov
 
PPTX
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Andrey Karpov
 
PDF
PVS-Studio in 2021 - Error Examples
Andrey Karpov
 
PDF
PVS-Studio in 2021 - Feature Overview
Andrey Karpov
 
PDF
PVS-Studio в 2021 - Примеры ошибок
Andrey Karpov
 
PDF
PVS-Studio в 2021
Andrey Karpov
 
PPTX
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Andrey Karpov
 
PPTX
Best Bugs from Games: Fellow Programmers' Mistakes
Andrey Karpov
 
PPTX
Does static analysis need machine learning?
Andrey Karpov
 
PPTX
Typical errors in code on the example of C++, C#, and Java
Andrey Karpov
 
PPTX
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
Andrey Karpov
 
PPTX
Game Engine Code Quality: Is Everything Really That Bad?
Andrey Karpov
 
PPTX
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov
 
PPTX
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
Andrey Karpov
 
PPTX
The Great and Mighty C++
Andrey Karpov
 
PPTX
Static code analysis: what? how? why?
Andrey Karpov
 
PDF
Zero, one, two, Freddy's coming for you
Andrey Karpov
 
PDF
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
Andrey Karpov
 
PDF
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
Andrey Karpov
 
60 антипаттернов для С++ программиста
Andrey Karpov
 
60 terrible tips for a C++ developer
Andrey Karpov
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Andrey Karpov
 
PVS-Studio in 2021 - Error Examples
Andrey Karpov
 
PVS-Studio in 2021 - Feature Overview
Andrey Karpov
 
PVS-Studio в 2021 - Примеры ошибок
Andrey Karpov
 
PVS-Studio в 2021
Andrey Karpov
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Andrey Karpov
 
Best Bugs from Games: Fellow Programmers' Mistakes
Andrey Karpov
 
Does static analysis need machine learning?
Andrey Karpov
 
Typical errors in code on the example of C++, C#, and Java
Andrey Karpov
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
Andrey Karpov
 
Game Engine Code Quality: Is Everything Really That Bad?
Andrey Karpov
 
C++ Code as Seen by a Hypercritical Reviewer
Andrey Karpov
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
Andrey Karpov
 
The Great and Mighty C++
Andrey Karpov
 
Static code analysis: what? how? why?
Andrey Karpov
 
Zero, one, two, Freddy's coming for you
Andrey Karpov
 
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
Andrey Karpov
 
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
Andrey Karpov
 

Recently uploaded (20)

DOCX
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
PPTX
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
PDF
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
PPTX
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
PDF
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
PDF
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
PDF
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
PPTX
Top Time Tracking Solutions for Accountants
oliviareed320
 
PPTX
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
PDF
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
PDF
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
PPTX
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
PDF
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
PPTX
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
PDF
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
PDF
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
DOCX
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
 
PDF
Complete WordPress Programming Guidance Book
Shabista Imam
 
PPTX
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
Top Time Tracking Solutions for Accountants
oliviareed320
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
 
Complete WordPress Programming Guidance Book
Shabista Imam
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 

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