SlideShare a Scribd company logo
1 of 38
1/38
How to create a high quality
static code analyzer
Sergey Khrenov (PVS-Studio)
2/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetics
•SelfTester: a check on real code
•Conclusions
Content
3/38
• It doesn’t replace but supplement
code reviews
• Detects errors in code without
running the program
• It helps to control the code quality
in large projects
Static analysis
4/38
PVS-Studio
• The classic C, C++, C# and Java static code analyzer
• It works in Windows, Linux and macOS
• It supports ARM platforms
• It has plugins for Visual Studio, IntelliJ IDEA, Jenkins,
Maven, Gradle, SonarQube
• It supports CWE, SEI CERT, MISRA standards
5/38
The example of an error in Mono code
6/38
The example of an error in Mono code
7/38
PVS-Studio: V3012 The '?:' operator, regardless of its conditional
expression, always returns one and the same value: Color.FromArgb
(150, 179, 225). ProfessionalColorTable.cs 258
The example of an error in Mono code
8/38
Issues
• Scientific character
• Different programming languages
• Cross-platforming
• Standards support
• Product specificity
• Classic testing methods are not enough
9/38
How to ensure quality?
• Joint code reviews (it works!)
• Static analysis
• Unit-tests
• UI-tests
• Functional tests
• Load testing
• Real project checks
10/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetic
•SelfTester: a check on real code
•Conclusions
Content
11/38
Roslyn
12/38
int x = 1;
Syntax tree
13/38
Semantic Model
 Obtaining information on the object
 Obtaining information on the object type
 Obtaining constant values
x = 1;
x
Semantic Model
System.Int32 x = 1;
14/38
Traversing tree nodes
public override void VisitIfStatement(IfStatementSyntax node)
{
base.VisitIfStatement(node);
}
public override void VisitForStatement(ForStatementSyntax node)
{
base.VisitForStatement(node);
}
….
15/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetics
•SelfTester: a check on real code
•Conclusions
Content
16/38
V3006 Diagnostic: missed throw
public void DoSomething(int index)
{
if (index < 0)
new ArgumentOutOfRangeException(); // <= V3006
else
....
}
// the correct code example:
throw new ArgumentOutOfRangeException();
17/38
1.Follow bypassing ObjectCreationExpressionSyntax type nodes
(creating an object using the new operator);
2.Check if the type of the object is System.Exception or a derived
one (use the Semantic model);
3.Check if the object is not used anywhere;
4.Issue a warning.
V3006 Diagnostic: missed throw
18/38
public class V3006CSharpRule : IVisitObjectCreationExpressionRule
{
....
public void VisitObjectCreationExpression(
SemanticModelAdapter model,
VisitInfo visitInfo,
ObjectCreationExpressionSyntax node,
AnalysisResults results)
{
....
}
}
V3006 Diagnostic: missed throw
19/38
Diagnostic development
1. Creating positive and negative tests
2. Prototype development that meets the tests’
requirements
3. Further diagnostic and tests development on a collection
of real projects (SelfTester)
4. Exception processing, false positives reducing
5. Re-running real projects, saving changes
20/38
Statistics
21/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetics
•SelfTester: a check on real code
•Conclusions
Content
22/38
Positive tests
23/38
Negative tests
24/38
Negative and positive tests
25/38
Negative and positive tests
26/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetic
•SelfTester: a check on real code
•Conclusions
Content
27/38
• The tool for batch-checking real projects
• SelfTester for С/С++ and C# uses a local set of
projects
• SelfTester for Java downloads the projects of a
particular version from the GitHub repository
PVS-Studio SelfTester
28/38
SelfTester tasks
• The main task is to detect defects of
PVS-Studio behavior
• Defects - difference in comparing to
previous analysis results
• Defects often represent expected
behavior
29/38
How to tell that the analyzer’s behavior has changed?
• The warnings composition has changed: the
new ones appeared, the old ones
disappeared
• The time spent on tests has changed
• Sometimes no change is a bad result (if you
have changed the core)
• There are errors after the check
30/38
PVS-Studio SelfTester (С#)
31/38
SelfTester: operation algorithm
32/38
Reports on detected errors (*.plog)
33/38
The result of reports’ comparison
34/38
Getting ready for production
• Further development on the basis
of user feedback (including the
internal users)
• Further development related to
change of the core behavior
(mechanisms finalization, new
language standards support, etc)
35/38
•The PVS-Studio static code analyzer
•What is inside of the C# analyzer
•Making and debugging diagnostics
•Internal tests, synthetic
•SelfTester: a check on real code
•Conclusions
Content
36/38
High-quality static analyzer
• A proprietary one
• Fast code processing
• Minimum false positives
• Advanced means of integrating
• Simple introduction in large projects
37/38
Any questions?
38/38
Sergey Khrenov
C# developer, PVS-Studio
khrenov@viva64.com
www.viva64.com
Contacts

More Related Content

What's hot

Random testing & prototyping
Random testing & prototypingRandom testing & prototyping
Random testing & prototyping
Vipul Rastogi
 
Assessing Model-Based Testing: An Empirical Study Conducted in Industry
Assessing Model-Based Testing: An Empirical Study Conducted in IndustryAssessing Model-Based Testing: An Empirical Study Conducted in Industry
Assessing Model-Based Testing: An Empirical Study Conducted in Industry
Dharmalingam Ganesan
 
Random testing
Random testingRandom testing
Random testing
Can KAYA
 
Automated Testing of NASA Software
Automated Testing of NASA SoftwareAutomated Testing of NASA Software
Automated Testing of NASA Software
Dharmalingam Ganesan
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
Dror Helper
 
Automock: Interaction-Based Mock Code Generation
Automock: Interaction-Based Mock Code GenerationAutomock: Interaction-Based Mock Code Generation
Automock: Interaction-Based Mock Code Generation
Sabrina Souto
 

What's hot (20)

Testing, fixing, and proving with contracts
Testing, fixing, and proving with contractsTesting, fixing, and proving with contracts
Testing, fixing, and proving with contracts
 
Random testing
Random testingRandom testing
Random testing
 
Random testing & prototyping
Random testing & prototypingRandom testing & prototyping
Random testing & prototyping
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Assessing Model-Based Testing: An Empirical Study Conducted in Industry
Assessing Model-Based Testing: An Empirical Study Conducted in IndustryAssessing Model-Based Testing: An Empirical Study Conducted in Industry
Assessing Model-Based Testing: An Empirical Study Conducted in Industry
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
NIO-ICSE2022.pptx
NIO-ICSE2022.pptxNIO-ICSE2022.pptx
NIO-ICSE2022.pptx
 
Parasoft fda software compliance part2
Parasoft fda software compliance   part2Parasoft fda software compliance   part2
Parasoft fda software compliance part2
 
Random testing
Random testingRandom testing
Random testing
 
Automated Testing of NASA Software
Automated Testing of NASA SoftwareAutomated Testing of NASA Software
Automated Testing of NASA Software
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Automock: Interaction-Based Mock Code Generation
Automock: Interaction-Based Mock Code GenerationAutomock: Interaction-Based Mock Code Generation
Automock: Interaction-Based Mock Code Generation
 
Testing
TestingTesting
Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Mutation testing in Java
Mutation testing in JavaMutation testing in Java
Mutation testing in Java
 
Winning the battle against Automated testing
Winning the battle against Automated testingWinning the battle against Automated testing
Winning the battle against Automated testing
 
Dsp
DspDsp
Dsp
 
Unit testing
Unit testing Unit testing
Unit testing
 

Similar to How to create a high quality static code analyzer

CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
Olivera Milenkovic
 
How to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator ProjectHow to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator Project
Simon Urli
 

Similar to How to create a high quality static code analyzer (20)

Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
Specifics of static analyzer development and testing
Specifics of static analyzer development and testingSpecifics of static analyzer development and testing
Specifics of static analyzer development and testing
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Getting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testingGetting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testing
 
The operation principles of PVS-Studio static code analyzer
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
 
CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back
 
EKON 23 Code_review_checklist
EKON 23 Code_review_checklistEKON 23 Code_review_checklist
EKON 23 Code_review_checklist
 
Mapping Detection Coverage
Mapping Detection CoverageMapping Detection Coverage
Mapping Detection Coverage
 
Tool up your lamp stack
Tool up your lamp stackTool up your lamp stack
Tool up your lamp stack
 
Tool Up Your LAMP Stack
Tool Up Your LAMP StackTool Up Your LAMP Stack
Tool Up Your LAMP Stack
 
Application of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data AnalysisApplication of the Actor Model to Large Scale NDE Data Analysis
Application of the Actor Model to Large Scale NDE Data Analysis
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
Tech Days 2015: Static Analysis CodePeer
Tech Days 2015: Static Analysis CodePeer Tech Days 2015: Static Analysis CodePeer
Tech Days 2015: Static Analysis CodePeer
 
Improving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis codeImproving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis code
 
SAST and Application Security: how to fight vulnerabilities in the code
SAST and Application Security: how to fight vulnerabilities in the codeSAST and Application Security: how to fight vulnerabilities in the code
SAST and Application Security: how to fight vulnerabilities in the code
 
How to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator ProjectHow to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator Project
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
 

More from Andrey Karpov

More from Andrey Karpov (20)

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
 
PVS-Studio в 2021
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021
 
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...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Typical errors in code on the example of C++, C#, and Java
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
 
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)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
 
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?
Game Engine Code Quality: Is Everything Really That Bad?
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
Static Code Analysis for Projects, Built on Unreal Engine
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
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
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
 
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...
PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerab...
 

Recently uploaded

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

How to create a high quality static code analyzer

  • 1. 1/38 How to create a high quality static code analyzer Sergey Khrenov (PVS-Studio)
  • 2. 2/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetics •SelfTester: a check on real code •Conclusions Content
  • 3. 3/38 • It doesn’t replace but supplement code reviews • Detects errors in code without running the program • It helps to control the code quality in large projects Static analysis
  • 4. 4/38 PVS-Studio • The classic C, C++, C# and Java static code analyzer • It works in Windows, Linux and macOS • It supports ARM platforms • It has plugins for Visual Studio, IntelliJ IDEA, Jenkins, Maven, Gradle, SonarQube • It supports CWE, SEI CERT, MISRA standards
  • 5. 5/38 The example of an error in Mono code
  • 6. 6/38 The example of an error in Mono code
  • 7. 7/38 PVS-Studio: V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: Color.FromArgb (150, 179, 225). ProfessionalColorTable.cs 258 The example of an error in Mono code
  • 8. 8/38 Issues • Scientific character • Different programming languages • Cross-platforming • Standards support • Product specificity • Classic testing methods are not enough
  • 9. 9/38 How to ensure quality? • Joint code reviews (it works!) • Static analysis • Unit-tests • UI-tests • Functional tests • Load testing • Real project checks
  • 10. 10/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetic •SelfTester: a check on real code •Conclusions Content
  • 12. 12/38 int x = 1; Syntax tree
  • 13. 13/38 Semantic Model  Obtaining information on the object  Obtaining information on the object type  Obtaining constant values x = 1; x Semantic Model System.Int32 x = 1;
  • 14. 14/38 Traversing tree nodes public override void VisitIfStatement(IfStatementSyntax node) { base.VisitIfStatement(node); } public override void VisitForStatement(ForStatementSyntax node) { base.VisitForStatement(node); } ….
  • 15. 15/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetics •SelfTester: a check on real code •Conclusions Content
  • 16. 16/38 V3006 Diagnostic: missed throw public void DoSomething(int index) { if (index < 0) new ArgumentOutOfRangeException(); // <= V3006 else .... } // the correct code example: throw new ArgumentOutOfRangeException();
  • 17. 17/38 1.Follow bypassing ObjectCreationExpressionSyntax type nodes (creating an object using the new operator); 2.Check if the type of the object is System.Exception or a derived one (use the Semantic model); 3.Check if the object is not used anywhere; 4.Issue a warning. V3006 Diagnostic: missed throw
  • 18. 18/38 public class V3006CSharpRule : IVisitObjectCreationExpressionRule { .... public void VisitObjectCreationExpression( SemanticModelAdapter model, VisitInfo visitInfo, ObjectCreationExpressionSyntax node, AnalysisResults results) { .... } } V3006 Diagnostic: missed throw
  • 19. 19/38 Diagnostic development 1. Creating positive and negative tests 2. Prototype development that meets the tests’ requirements 3. Further diagnostic and tests development on a collection of real projects (SelfTester) 4. Exception processing, false positives reducing 5. Re-running real projects, saving changes
  • 21. 21/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetics •SelfTester: a check on real code •Conclusions Content
  • 26. 26/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetic •SelfTester: a check on real code •Conclusions Content
  • 27. 27/38 • The tool for batch-checking real projects • SelfTester for С/С++ and C# uses a local set of projects • SelfTester for Java downloads the projects of a particular version from the GitHub repository PVS-Studio SelfTester
  • 28. 28/38 SelfTester tasks • The main task is to detect defects of PVS-Studio behavior • Defects - difference in comparing to previous analysis results • Defects often represent expected behavior
  • 29. 29/38 How to tell that the analyzer’s behavior has changed? • The warnings composition has changed: the new ones appeared, the old ones disappeared • The time spent on tests has changed • Sometimes no change is a bad result (if you have changed the core) • There are errors after the check
  • 32. 32/38 Reports on detected errors (*.plog)
  • 33. 33/38 The result of reports’ comparison
  • 34. 34/38 Getting ready for production • Further development on the basis of user feedback (including the internal users) • Further development related to change of the core behavior (mechanisms finalization, new language standards support, etc)
  • 35. 35/38 •The PVS-Studio static code analyzer •What is inside of the C# analyzer •Making and debugging diagnostics •Internal tests, synthetic •SelfTester: a check on real code •Conclusions Content
  • 36. 36/38 High-quality static analyzer • A proprietary one • Fast code processing • Minimum false positives • Advanced means of integrating • Simple introduction in large projects
  • 38. 38/38 Sergey Khrenov C# developer, PVS-Studio khrenov@viva64.com www.viva64.com Contacts