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

PPTX
No more dead kittens - Clean Code
PPTX
FaultHunter workshop (SourceMeter for SonarQube plugin module)
PDF
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
PDF
Why Have The Specifications Been Based On Java™ Technology? - P Kriens
PDF
Code Coverage Revised : EclEmma on JaCoCo
PDF
Vlsi lab manual_new
PDF
PPTX
Code Smells Part 1: Basic Smells
No more dead kittens - Clean Code
FaultHunter workshop (SourceMeter for SonarQube plugin module)
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Why Have The Specifications Been Based On Java™ Technology? - P Kriens
Code Coverage Revised : EclEmma on JaCoCo
Vlsi lab manual_new
Code Smells Part 1: Basic Smells

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

PPT
PPT
PDF
All about PVS-Studio
PDF
PVS-Studio advertisement - static analysis of C/C++ code
PDF
Firmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
PPTX
Production Debugging at Code Camp Philly
PDF
From V8 to Modern Compilers
PDF
Developer-Friendly CI / CD for Kubernetes
PDF
Waiting for a cyber range exercise is not enough
PPT
01 Introduction to programming
PDF
Embedding V8 in Android apps with Ejecta-V8
PDF
How I learned to stop worrying and love embedding JavaScript
PDF
Profiling distributed Java applications
PPTX
Static analysis as means of improving code quality
PDF
C# 4.0 - Whats New
PDF
Letter to a Junior Developer: The Engineering Side of Programming
PPTX
OVerview of Jenkins - A WIP pPT that needs to be refined
PPTX
Continuous Delivery for IT Operations Teams
PDF
OpenCV (Open source computer vision)
PDF
Be armed to the teeth to maintain a high quality iOS code
All about PVS-Studio
PVS-Studio advertisement - static analysis of C/C++ code
Firmware Co-Design & Development for IP Cores in C++/SystemC using Verilator
Production Debugging at Code Camp Philly
From V8 to Modern Compilers
Developer-Friendly CI / CD for Kubernetes
Waiting for a cyber range exercise is not enough
01 Introduction to programming
Embedding V8 in Android apps with Ejecta-V8
How I learned to stop worrying and love embedding JavaScript
Profiling distributed Java applications
Static analysis as means of improving code quality
C# 4.0 - Whats New
Letter to a Junior Developer: The Engineering Side of Programming
OVerview of Jenkins - A WIP pPT that needs to be refined
Continuous Delivery for IT Operations Teams
OpenCV (Open source computer vision)
Be armed to the teeth to maintain a high quality iOS code

More from Andrey Karpov (20)

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

Recently uploaded (20)

PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
top salesforce developer skills in 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Understanding Forklifts - TECH EHS Solution
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
System and Network Administraation Chapter 3
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Nekopoi APK 2025 free lastest update
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Introduction to Artificial Intelligence
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ISO 45001 Occupational Health and Safety Management System
top salesforce developer skills in 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Softaken Excel to vCard Converter Software.pdf
CHAPTER 2 - PM Management and IT Context
Understanding Forklifts - TECH EHS Solution
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
System and Network Administraation Chapter 3
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions
Nekopoi APK 2025 free lastest update
Wondershare Filmora 15 Crack With Activation Key [2025
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
VVF-Customer-Presentation2025-Ver1.9.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Online Work Permit System for Fast Permit Processing
Introduction to Artificial Intelligence
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

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