SlideShare a Scribd company logo
1 of 106
Typical errors in code on the example of
C++, C#, and Java
Information Technology Video Developer Network
Информационный
видеосервис
для
разработчиков
программного
обеспечения
http://itvdn.com
Георгий Грибков
About the speaker
Information Technology Video Developer Network http://itvdn.com
ITVDN
C++ developer of the PVS-Studio static code analyzer
• Develops the analyzer core, new diagnostics, supports users.
• Introduced PVS-Studio in the godbolt.org online compiler.
• Wrote articles for the Habr website and gave talks at IT conferences,
related to searching for bugs in code.
Typical errors in code on the example of C++, C#, and Java
Agenda
Information Technology Video Developer Network http://itvdn.com
ITVDN
1. Objectives of this webinar
2. How we detected error patterns
3. Patterns themselves and how to avoid them:
3.1 Copy-paste and last line effect
3.2 if (A) {...} else if (A)
3.3 Errors in checks
3.4 Array index out of bounds
3.5 Operator precedence
3.6 Typos that are hard to spot
4. How to use static analysis properly
5. Conclusion
6. Q&A
Заключение
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
More than 50 video courses for C# developers at ITVDN
C# Basics
Author: Alexander Shevchuk
Duration: 16 h 3 mins
9 lessons
C# Basic (OOP)
Author: Alexander Shevchuk
Duration: 31 h 26 mins
18 lessons
C# for professionals
Author: Oleg Kulygin
Duration: 19 h 38 mins
17 lessons
C# Generics
Author: Nikolay Melnichuk
Duration: 4 h 49 mins
7 lessons
Unit testing in C#
Author: Dmitry Okhrimenko
Duration: 3 h 48 mins
3 lessons
.NET Apps
Refactoring
Author: David Boyarov
Duration: 6 h 41 mins, 5 lessons
Information Technology Video Developer Network http://itvdn.com
ITVDN
More than 26 video courses for Java developers at ITVDN
Java Starter
Author: Evgeny Tikhonov
Duration: 9 h 46 mins
9 lessons
Java Essential
Author: Evgeny Tikhonov
Duration: 11 h 10 mins
10 lessons
Java Professional
Author : Evgeny Tikhonov
Duration: 20 h 18 mins
15 lessons
SOLID principles in Java
Author: Andrey Fok
Duration: 2 h 45 mins
5 lessons
Unit testing in Java with JUnit
Author: Mikhail Skafenko
Duration: 2 h 33 mins
7 lessons
Java EE Basics
Author: Andrey Bondarenko
Duration: 18 h 50 mins
12 lessons
Information Technology Video Developer Network http://itvdn.com
ITVDN
Video courses for C++ developers at ITVDN
C++ Starter
Author: Vladimir Vinogradov
Duration: 8 h 13 mins
13 lessons
QT Framework
Author: Ruslan Larionenko
Duration: 6 h 27 mins
10 lessons
C++ Essential
Author: Kirill Chernega
Duration: 4 h 38 mins
8 lessons
C++Advanced
Author: Kirill Chernega
Duration: 8 h 17 mins
11 lessons
Complete practical tasks in C++
Author: Naumenko Alexander
Duration: 4 h 39 mins, 7 lessons
STL - Standard Template Library
Author: Pavlenko Alexander
Duration: 7 h 5 mins, 12 lessons
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
*
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
BUGS ARE EVERYWHERE!
Typical errors in code on the example of C++, C#, and Java
How to avoid errors
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Warn developers of typical problems
• Use tools to automatically search for errors
Typical errors in code on the example of C++, C#, and Java
Objectives of this webinar
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Demonstrate typical error patterns in code
• Show how to use static analysis properly
Typical errors in code on the example of C++, C#, and Java
2. How we detected error patterns
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
What is static analysis
Information Technology Video Developer Network http://itvdn.com
ITVDN
Static analysis is automated code review.
Typical errors in code on the example of C++, C#, and Java
What is static analysis
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Examples of static analyzers
Information Technology Video Developer Network http://itvdn.com
ITVDN
• PVS-Studio
• Cppcheck
• Infer
• IntelliJ IDEA
• Clang Static Analyzer
• FindBugs
• ...
Long list of static analyzers:
Typical errors in code on the example of C++, C#, and Java
How we detected error patterns
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Found errors
380 13747
Checked
projects
Detected
errors
Check out the base of errors we found:
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
3. Patterns themselves and how to avoid them
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Pattern № 1:
Copy-paste and last line effect
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V6039 There are two 'if' statements with identical
conditional expressions. The first 'if' statement
contains method return. This means that the
second 'if' statement is senseless.
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Clang (C++)
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Clang (C++)
PVS-Studio warning: V501 There are identical sub-expressions
SM.getExpansionColumnNumber(ContainerREnd)' to the left and to the right of the '>=' operator.
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Clang (C++)
PVS-Studio warning: V501 There are identical sub-expressions
SM.getExpansionColumnNumber(ContainerREnd)' to the left and to the right of the '>=' operator.
Typical errors in code on the example of C++, C#, and Java
Xenko Game Engine (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Xenko Game Engine (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning: V3001 There are
identical sub-expressions 'box.Maximum.X
- box.Minimum.X > sphere.Radius' to the
left and to the right of the '&&' operator.
Typical errors in code on the example of C++, C#, and Java
Pattern № 1: Copy-paste and last line effect
Information Technology Video Developer Network http://itvdn.com
ITVDN
• We selected 84 examples of erroneous code
written with copy-paste
• 43 of them had an error in the last line!
• It is more than 50%!
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Stop copy-pasting
• Copy-pasting in programming is pure evil!
• If you dare to – be extremely attentive
How to avoid
Typical errors in code on the example of C++, C#, and Java
Pattern № 2.
if (A) {...} else if (A)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V6003 The use of 'if (A) {....} else if (A)
{....}' pattern was detected. There is a
probability of logical error presence.
Typical errors in code on the example of C++, C#, and Java
Chromium (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Chromium (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V517 The use of 'if (A) {...} else if (A)
{...}' pattern was detected. There is a
probability of logical error presence.
Check lines: 61, 63.
Typical errors in code on the example of C++, C#, and Java
CryEngine V (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
CryEngine V (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V517 The use of 'if (A) {...} else if (A)
{...}' pattern was detected. There is a
probability of logical error presence.
Check lines: 266, 268.
Typical errors in code on the example of C++, C#, and Java
CryEngine V (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V517 The use of 'if (A) {...} else if (A)
{...}' pattern was detected. There is a
probability of logical error presence.
Check lines: 266, 268.
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
MonoDevelop (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V3021 There are two 'if' statements
with identical conditional
expressions. The first 'if' statement
contains method return. This means
that the second 'if' statement is
senseless.
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Try to do best not to copy-paste
• If you’re still going to copy-paste, copy non-compiled constructions.
• Example:
if (value == _)
return _;
How to avoid?
Typical errors in code on the example of C++, C#, and Java
Pattern № 3.
Errors in checks
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Unity (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Unity (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V3063 A part of conditional
expression is always true if it is
evaluated: pageSize <= 1000.
Typical errors in code on the example of C++, C#, and Java
Bullet - the engine of Red Dead Redemption (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Bullet - the engine of Red Dead Redemption (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V709 Suspicious comparison found:
'f0 == f1 == m_fractureBodies.size()’.
Remember that
'a == b == c’
is not equal to
'a == b && b == c'.
Typical errors in code on the example of C++, C#, and Java
Apache Hive (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Apache Hive (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning: V6030 The method located to the right of the '|' operator will be called regardless of
the value of the left operand. Perhaps, it is better to use '||'.
Typical errors in code on the example of C++, C#, and Java
Chromium (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Chromium (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Chromium (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warnings:
 V547 Expression
'time.month <=
kDaysInMonth[time.month] + 1' is
always true.
 V547 Expression
'time.month <=
kDaysInMonth[time.month]’
is always true.
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
• «Pay attention!» won’t work every time 
• Try backup tools
How to avoid
Typical errors in code on the example of C++, C#, and Java
Pattern № 4.
Array index out of bounds
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Stickies (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Stickies (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V557 Array overrun is possible. The
'64' index is pointing beyond array
bound. stickies stickies.cpp
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning: V6025 Possibly index '(int) x' is out of bounds.
Typical errors in code on the example of C++, C#, and Java
Elasticsearch (Java)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning: V6025 Possibly index '(int) x' is out of bounds.
Typical errors in code on the example of C++, C#, and Java
IPP Samples (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
IPP Samples (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
IPP Samples (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
IPP Samples (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
IPP Samples (C++)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V557 Array overrun is possible. The '30'
index is pointing beyond array bound.
Typical errors in code on the example of C++, C#, and Java
FastReport (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
FastReport (C#)
Information Technology Video Developer Network http://itvdn.com
ITVDN
PVS-Studio warning:
V3106 Possible negative index value. The value
of 'idx' index could reach -1.
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Be careful when you add '0’ to the end of the string
• Do you get an external index? Make sure you check it!
• Don’t mix up '>' ('<‘) and '>=' ('<=‘) when comparing the index with the array size
How to avoid
Typical errors in code on the example of C++, C#, and Java
4. How to use static analysis properly
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
When you should perform static analysis
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
When you should perform static analysis
Information Technology Video Developer Network http://itvdn.com
ITVDN
Static analysis
Typical errors in code on the example of C++, C#, and Java
How to make the most of static analysis
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Apply static analysis at early stages
• Analyze regularly
Typical errors in code on the example of C++, C#, and Java
Proprietary development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Proprietary development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Proprietary development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Proprietary development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Proprietary development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Corporate development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Open-source development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Open-source development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Open-source development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Open-source development
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
More about analysis of commits and pull-requests
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
5. Conclusion
Information Technology Video Developer Network http://itvdn.com
ITVDN
Typical errors in code on the example of C++, C#, and Java
Typical error patterns in code
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Copy-paste and last line effect
• if (A) {...} else if (A)
• Errors in checks
• Array index out of bounds
• … (the list gradually expands)
Typical errors in code on the example of C++, C#, and Java
How to avoid typical errors
Information Technology Video Developer Network http://itvdn.com
ITVDN
• Stop copy-pasting!
• Seriously, stop copy-pasting!
• Pay attention to checks, even small and short ones.
• Carefully check array indexes.
• Regularly use static analysis.
Typical errors in code on the example of C++, C#, and Java
Free PVS-Studio license for students
Information Technology Video Developer Network http://itvdn.com
ITVDN
https://bit.ly/pvs-student
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Q&A
Typical errors in code on the example of C++, C#, and Java
Information Technology Video Developer Network http://itvdn.com
ITVDN
Watch our video lessons on C++
At ITVDN you’ll find a collection of video courses and webinars for C++ developers.
Go to ITVDN.com and watch our video lessons right now!
IT VIDEO DEVELOPERS NETWORK
Information Technology Video Developer Network http://itvdn.com
ITVDN

More Related Content

Similar to Typical errors in code on the example of C++, C#, and Java

All about PVS-Studio
All about PVS-StudioAll about PVS-Studio
All about PVS-StudioPVS-Studio
 
PVS-Studio advertisement - static analysis of C/C++ code
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
 
Firmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
Firmware Co-Design & Development for IP Cores in C++/SystemC using VerilatorFirmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
Firmware Co-Design & Development for IP Cores in C++/SystemC using VerilatorSeyed Amir Alavi
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyBrian Lyttle
 
From V8 to Modern Compilers
From V8 to Modern CompilersFrom V8 to Modern Compilers
From V8 to Modern CompilersMin-Yih Hsu
 
Developer-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDeveloper-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDevOps Indonesia
 
Waiting for a cyber range exercise is not enough
Waiting for a cyber range exercise is not enoughWaiting for a cyber range exercise is not enough
Waiting for a cyber range exercise is not enoughOlafSchwarz1
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programmingmaznabili
 
How I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptHow I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptKevin Read
 
Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Kevin Read
 
Profiling distributed Java applications
Profiling distributed Java applicationsProfiling distributed Java applications
Profiling distributed Java applicationsConstantine Slisenka
 
Static analysis as means of improving code quality
Static analysis as means of improving code quality Static analysis as means of improving code quality
Static analysis as means of improving code quality Andrey Karpov
 
Letter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLazar Kovacevic
 
Continuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations TeamsContinuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations TeamsMark Rendell
 
OpenCV (Open source computer vision)
OpenCV (Open source computer vision)OpenCV (Open source computer vision)
OpenCV (Open source computer vision)Chetan Allapur
 
Be armed to the teeth to maintain a high quality iOS code
Be armed to the teeth to maintain a high quality iOS codeBe armed to the teeth to maintain a high quality iOS code
Be armed to the teeth to maintain a high quality iOS codeAnastasia Kazakova
 
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise ApplicationsDaniel Oh
 

Similar to Typical errors in code on the example of C++, C#, and Java (20)

Aicas, Inc.
Aicas, Inc.Aicas, Inc.
Aicas, Inc.
 
aicas, inc.
aicas, inc.aicas, inc.
aicas, inc.
 
All about PVS-Studio
All about PVS-StudioAll about PVS-Studio
All about PVS-Studio
 
PVS-Studio advertisement - static analysis of C/C++ code
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
 
Firmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
Firmware Co-Design & Development for IP Cores in C++/SystemC using VerilatorFirmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
Firmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
From V8 to Modern Compilers
From V8 to Modern CompilersFrom V8 to Modern Compilers
From V8 to Modern Compilers
 
Developer-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for KubernetesDeveloper-Friendly CI / CD for Kubernetes
Developer-Friendly CI / CD for Kubernetes
 
Waiting for a cyber range exercise is not enough
Waiting for a cyber range exercise is not enoughWaiting for a cyber range exercise is not enough
Waiting for a cyber range exercise is not enough
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
How I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScriptHow I learned to stop worrying and love embedding JavaScript
How I learned to stop worrying and love embedding JavaScript
 
Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8Embedding V8 in Android apps with Ejecta-V8
Embedding V8 in Android apps with Ejecta-V8
 
Profiling distributed Java applications
Profiling distributed Java applicationsProfiling distributed Java applications
Profiling distributed Java applications
 
Static analysis as means of improving code quality
Static analysis as means of improving code quality Static analysis as means of improving code quality
Static analysis as means of improving code quality
 
C# 4.0 - Whats New
C# 4.0 - Whats NewC# 4.0 - Whats New
C# 4.0 - Whats New
 
Letter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of Programming
 
Continuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations TeamsContinuous Delivery for IT Operations Teams
Continuous Delivery for IT Operations Teams
 
OpenCV (Open source computer vision)
OpenCV (Open source computer vision)OpenCV (Open source computer vision)
OpenCV (Open source computer vision)
 
Be armed to the teeth to maintain a high quality iOS code
Be armed to the teeth to maintain a high quality iOS codeBe armed to the teeth to maintain a high quality iOS code
Be armed to the teeth to maintain a high quality iOS code
 
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications[RHFSeoul2017]6 Steps to Transform Enterprise Applications
[RHFSeoul2017]6 Steps to Transform Enterprise Applications
 

More from Andrey Karpov

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программистаAndrey Karpov
 
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++ developerAndrey Karpov
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Andrey Karpov
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewAndrey Karpov
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок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...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Andrey Karpov
 
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' MistakesAndrey Karpov
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?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)
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?
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 Karpov
 
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 ReviewerAndrey Karpov
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
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 SoftwareAndrey Karpov
 
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 EngineAndrey Karpov
 
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 SystemsAndrey Karpov
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++Andrey Karpov
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
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 youAndrey Karpov
 
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 DevOpsAndrey 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
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
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
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
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
 
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
 

Recently uploaded

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Lecture # 8 software design and architecture (SDA).ppt
Lecture # 8 software design and architecture (SDA).pptLecture # 8 software design and architecture (SDA).ppt
Lecture # 8 software design and architecture (SDA).pptesrabilgic2
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Lecture # 8 software design and architecture (SDA).ppt
Lecture # 8 software design and architecture (SDA).pptLecture # 8 software design and architecture (SDA).ppt
Lecture # 8 software design and architecture (SDA).ppt
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

Typical errors in code on the example of C++, C#, and Java

  • 1. Typical errors in code on the example of C++, C#, and Java Information Technology Video Developer Network Информационный видеосервис для разработчиков программного обеспечения http://itvdn.com
  • 2. Георгий Грибков About the speaker Information Technology Video Developer Network http://itvdn.com ITVDN C++ developer of the PVS-Studio static code analyzer • Develops the analyzer core, new diagnostics, supports users. • Introduced PVS-Studio in the godbolt.org online compiler. • Wrote articles for the Habr website and gave talks at IT conferences, related to searching for bugs in code. Typical errors in code on the example of C++, C#, and Java
  • 3. Agenda Information Technology Video Developer Network http://itvdn.com ITVDN 1. Objectives of this webinar 2. How we detected error patterns 3. Patterns themselves and how to avoid them: 3.1 Copy-paste and last line effect 3.2 if (A) {...} else if (A) 3.3 Errors in checks 3.4 Array index out of bounds 3.5 Operator precedence 3.6 Typos that are hard to spot 4. How to use static analysis properly 5. Conclusion 6. Q&A Заключение Typical errors in code on the example of C++, C#, and Java
  • 4. Information Technology Video Developer Network http://itvdn.com ITVDN More than 50 video courses for C# developers at ITVDN C# Basics Author: Alexander Shevchuk Duration: 16 h 3 mins 9 lessons C# Basic (OOP) Author: Alexander Shevchuk Duration: 31 h 26 mins 18 lessons C# for professionals Author: Oleg Kulygin Duration: 19 h 38 mins 17 lessons C# Generics Author: Nikolay Melnichuk Duration: 4 h 49 mins 7 lessons Unit testing in C# Author: Dmitry Okhrimenko Duration: 3 h 48 mins 3 lessons .NET Apps Refactoring Author: David Boyarov Duration: 6 h 41 mins, 5 lessons
  • 5. Information Technology Video Developer Network http://itvdn.com ITVDN More than 26 video courses for Java developers at ITVDN Java Starter Author: Evgeny Tikhonov Duration: 9 h 46 mins 9 lessons Java Essential Author: Evgeny Tikhonov Duration: 11 h 10 mins 10 lessons Java Professional Author : Evgeny Tikhonov Duration: 20 h 18 mins 15 lessons SOLID principles in Java Author: Andrey Fok Duration: 2 h 45 mins 5 lessons Unit testing in Java with JUnit Author: Mikhail Skafenko Duration: 2 h 33 mins 7 lessons Java EE Basics Author: Andrey Bondarenko Duration: 18 h 50 mins 12 lessons
  • 6. Information Technology Video Developer Network http://itvdn.com ITVDN Video courses for C++ developers at ITVDN C++ Starter Author: Vladimir Vinogradov Duration: 8 h 13 mins 13 lessons QT Framework Author: Ruslan Larionenko Duration: 6 h 27 mins 10 lessons C++ Essential Author: Kirill Chernega Duration: 4 h 38 mins 8 lessons C++Advanced Author: Kirill Chernega Duration: 8 h 17 mins 11 lessons Complete practical tasks in C++ Author: Naumenko Alexander Duration: 4 h 39 mins, 7 lessons STL - Standard Template Library Author: Pavlenko Alexander Duration: 7 h 5 mins, 12 lessons
  • 7. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 8. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 9. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 10. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 11. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 12. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 13. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 14. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 15. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 16. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 17. Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 18. Information Technology Video Developer Network http://itvdn.com ITVDN * Typical errors in code on the example of C++, C#, and Java
  • 19. Information Technology Video Developer Network http://itvdn.com ITVDN BUGS ARE EVERYWHERE! Typical errors in code on the example of C++, C#, and Java
  • 20. How to avoid errors Information Technology Video Developer Network http://itvdn.com ITVDN • Warn developers of typical problems • Use tools to automatically search for errors Typical errors in code on the example of C++, C#, and Java
  • 21. Objectives of this webinar Information Technology Video Developer Network http://itvdn.com ITVDN • Demonstrate typical error patterns in code • Show how to use static analysis properly Typical errors in code on the example of C++, C#, and Java
  • 22. 2. How we detected error patterns Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 23. What is static analysis Information Technology Video Developer Network http://itvdn.com ITVDN Static analysis is automated code review. Typical errors in code on the example of C++, C#, and Java
  • 24. What is static analysis Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 25. Examples of static analyzers Information Technology Video Developer Network http://itvdn.com ITVDN • PVS-Studio • Cppcheck • Infer • IntelliJ IDEA • Clang Static Analyzer • FindBugs • ... Long list of static analyzers: Typical errors in code on the example of C++, C#, and Java
  • 26. How we detected error patterns Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java Found errors 380 13747 Checked projects Detected errors
  • 27. Check out the base of errors we found: Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 28. 3. Patterns themselves and how to avoid them Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 29. Pattern № 1: Copy-paste and last line effect Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 30. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 31. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V6039 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. Typical errors in code on the example of C++, C#, and Java
  • 32. Information Technology Video Developer Network http://itvdn.com ITVDN Clang (C++) Typical errors in code on the example of C++, C#, and Java
  • 33. Information Technology Video Developer Network http://itvdn.com ITVDN Clang (C++) PVS-Studio warning: V501 There are identical sub-expressions SM.getExpansionColumnNumber(ContainerREnd)' to the left and to the right of the '>=' operator. Typical errors in code on the example of C++, C#, and Java
  • 34. Information Technology Video Developer Network http://itvdn.com ITVDN Clang (C++) PVS-Studio warning: V501 There are identical sub-expressions SM.getExpansionColumnNumber(ContainerREnd)' to the left and to the right of the '>=' operator. Typical errors in code on the example of C++, C#, and Java
  • 35. Xenko Game Engine (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 36. Xenko Game Engine (C#) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V3001 There are identical sub-expressions 'box.Maximum.X - box.Minimum.X > sphere.Radius' to the left and to the right of the '&&' operator. Typical errors in code on the example of C++, C#, and Java
  • 37. Pattern № 1: Copy-paste and last line effect Information Technology Video Developer Network http://itvdn.com ITVDN • We selected 84 examples of erroneous code written with copy-paste • 43 of them had an error in the last line! • It is more than 50%! Typical errors in code on the example of C++, C#, and Java
  • 38. Information Technology Video Developer Network http://itvdn.com ITVDN • Stop copy-pasting • Copy-pasting in programming is pure evil! • If you dare to – be extremely attentive How to avoid Typical errors in code on the example of C++, C#, and Java
  • 39. Pattern № 2. if (A) {...} else if (A) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 40. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 41. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V6003 The use of 'if (A) {....} else if (A) {....}' pattern was detected. There is a probability of logical error presence. Typical errors in code on the example of C++, C#, and Java
  • 42. Chromium (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 43. Chromium (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 61, 63. Typical errors in code on the example of C++, C#, and Java
  • 44. CryEngine V (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 45. CryEngine V (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 266, 268. Typical errors in code on the example of C++, C#, and Java
  • 46. CryEngine V (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 266, 268. Typical errors in code on the example of C++, C#, and Java
  • 47. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 48. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 49. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 50. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 51. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 52. MonoDevelop (C#) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. Typical errors in code on the example of C++, C#, and Java
  • 53. Information Technology Video Developer Network http://itvdn.com ITVDN • Try to do best not to copy-paste • If you’re still going to copy-paste, copy non-compiled constructions. • Example: if (value == _) return _; How to avoid? Typical errors in code on the example of C++, C#, and Java
  • 54. Pattern № 3. Errors in checks Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 55. Unity (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 56. Unity (C#) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V3063 A part of conditional expression is always true if it is evaluated: pageSize <= 1000. Typical errors in code on the example of C++, C#, and Java
  • 57. Bullet - the engine of Red Dead Redemption (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 58. Bullet - the engine of Red Dead Redemption (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V709 Suspicious comparison found: 'f0 == f1 == m_fractureBodies.size()’. Remember that 'a == b == c’ is not equal to 'a == b && b == c'. Typical errors in code on the example of C++, C#, and Java
  • 59. Apache Hive (Java) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 60. Apache Hive (Java) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V6030 The method located to the right of the '|' operator will be called regardless of the value of the left operand. Perhaps, it is better to use '||'. Typical errors in code on the example of C++, C#, and Java
  • 61. Chromium (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 62. Chromium (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 63. Chromium (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warnings:  V547 Expression 'time.month <= kDaysInMonth[time.month] + 1' is always true.  V547 Expression 'time.month <= kDaysInMonth[time.month]’ is always true. Typical errors in code on the example of C++, C#, and Java
  • 64. Information Technology Video Developer Network http://itvdn.com ITVDN • «Pay attention!» won’t work every time  • Try backup tools How to avoid Typical errors in code on the example of C++, C#, and Java
  • 65. Pattern № 4. Array index out of bounds Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 66. Stickies (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 67. Stickies (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V557 Array overrun is possible. The '64' index is pointing beyond array bound. stickies stickies.cpp Typical errors in code on the example of C++, C#, and Java
  • 68. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 69. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V6025 Possibly index '(int) x' is out of bounds. Typical errors in code on the example of C++, C#, and Java
  • 70. Elasticsearch (Java) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V6025 Possibly index '(int) x' is out of bounds. Typical errors in code on the example of C++, C#, and Java
  • 71. IPP Samples (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 72. IPP Samples (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 73. IPP Samples (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 74. IPP Samples (C++) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 75. IPP Samples (C++) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V557 Array overrun is possible. The '30' index is pointing beyond array bound. Typical errors in code on the example of C++, C#, and Java
  • 76. FastReport (C#) Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 77. FastReport (C#) Information Technology Video Developer Network http://itvdn.com ITVDN PVS-Studio warning: V3106 Possible negative index value. The value of 'idx' index could reach -1. Typical errors in code on the example of C++, C#, and Java
  • 78. Information Technology Video Developer Network http://itvdn.com ITVDN • Be careful when you add '0’ to the end of the string • Do you get an external index? Make sure you check it! • Don’t mix up '>' ('<‘) and '>=' ('<=‘) when comparing the index with the array size How to avoid Typical errors in code on the example of C++, C#, and Java
  • 79. 4. How to use static analysis properly Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 80. When you should perform static analysis Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 81. When you should perform static analysis Information Technology Video Developer Network http://itvdn.com ITVDN Static analysis Typical errors in code on the example of C++, C#, and Java
  • 82. How to make the most of static analysis Information Technology Video Developer Network http://itvdn.com ITVDN • Apply static analysis at early stages • Analyze regularly Typical errors in code on the example of C++, C#, and Java
  • 83. Proprietary development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 84. Proprietary development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 85. Proprietary development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 86. Proprietary development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 87. Proprietary development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 88. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 89. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 90. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 91. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 92. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 93. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 94. Corporate development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 95. Open-source development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 96. Open-source development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 97. Open-source development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 98. Open-source development Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 99. More about analysis of commits and pull-requests Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 100. 5. Conclusion Information Technology Video Developer Network http://itvdn.com ITVDN Typical errors in code on the example of C++, C#, and Java
  • 101. Typical error patterns in code Information Technology Video Developer Network http://itvdn.com ITVDN • Copy-paste and last line effect • if (A) {...} else if (A) • Errors in checks • Array index out of bounds • … (the list gradually expands) Typical errors in code on the example of C++, C#, and Java
  • 102. How to avoid typical errors Information Technology Video Developer Network http://itvdn.com ITVDN • Stop copy-pasting! • Seriously, stop copy-pasting! • Pay attention to checks, even small and short ones. • Carefully check array indexes. • Regularly use static analysis. Typical errors in code on the example of C++, C#, and Java
  • 103. Free PVS-Studio license for students Information Technology Video Developer Network http://itvdn.com ITVDN https://bit.ly/pvs-student Typical errors in code on the example of C++, C#, and Java
  • 104. Information Technology Video Developer Network http://itvdn.com ITVDN Q&A Typical errors in code on the example of C++, C#, and Java
  • 105. Information Technology Video Developer Network http://itvdn.com ITVDN Watch our video lessons on C++ At ITVDN you’ll find a collection of video courses and webinars for C++ developers. Go to ITVDN.com and watch our video lessons right now!
  • 106. IT VIDEO DEVELOPERS NETWORK Information Technology Video Developer Network http://itvdn.com ITVDN