How to fight bugs in legacy code?
Should you do it at all?
What to do if there are hundreds or even thousands of errors?(that’s usually the case)
How to avoid spending a plethora of man-hours on this?
And still, how did you work with Unreal Engine?
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
1. How to Fix Hundreds of Bugs in
Legacy Code and Not Die
(Unreal Engine 4)
George Gribkov
2. About Me:
George Gribkov
A C++ developer and developer of the PVS-
Studio static code analyzer
I help our clients fight errors
I write articles on looking
for bugs in open-source
projects.
gribkov@viva64.com
2
4. How to fight bugs in legacy code?
Should you do it at all?
Overview
4
5. How to fight bugs in legacy code?
Should you do it at all?
What to do if there are hundreds or even thousands
of errors?
Overview
5
6. How to fight bugs in legacy code?
Should you do it at all?
What to do if there are hundreds or even thousands
of errors?
(that’s usually the case)
Overview
6
7. How to fight bugs in legacy code?
Should you do it at all?
What to do if there are hundreds or even thousands of errors?
(that’s usually the case)
How to avoid spending a plethora of man-hours on this?
Overview
7
8. How to fight bugs in legacy code?
Should you do it at all?
What to do if there are hundreds or even thousands of errors?
(that’s usually the case)
How to avoid spending a plethora of man-hours on this?
And still, how did you work with Unreal Engine?
Overview
8
25. 1. Set up continuous analysis
2.
3.
What’s a Good Way to Deal With Old Bugs?
25
26. 1. Set up continuous analysis
2. Protect yourself from new bugs
3.
What’s a Good Way to Deal With Old Bugs?
26
27. 1. Set up continuous analysis
2. Protect yourself from new bugs
3. Gradually go through the analyzer’s report line-
by-line, making sure to spend few resources
each time.
What’s a Good Way to Deal With Old Bugs?
27
28. How Our Two Developers Fixed 2000 Bugs, That Our
Analyzer Reported in Unreal Engine 4, in 17 Business
Days
28
30. My boss found errors in UE 4
and wrote an article
Developers from Epic Games
liked it a lot
They wanted to fix more bugs
and trusted that matter to us
How It Started
30
32. The most convenient approach: check the
project through Visual Studio
Luckily, UE has a set of scripts to generate
.vcxproj files
The First Check
32
34. 1.Generate project files
2.Build the project
3.Start the analysis from Visual
Studio
4.???????
5.EPIC GAMES FAIL
The First Analysis Attempt
34
35. Generated project files are just a wrapper
These wrappers call the Unreal Build Tool
Unreal Build Tool starts cl.exe (or clang, for Linux
builds)
How the Unreal Engine Project Is Built
35
36. Generated project files are just a wrapper
These wrappers call the Unreal Build Tool
Unreal Build Tool starts cl.exe (or clang, for Linux
builds)
Because of all these layers the analyzer cannot
collect the parameters required for compilation
How Unreal Engine Project Is Built
36
38. What if we try to catch compiler calls directly?
The Second Check
38
39. What if we try to catch compiler calls directly?
It’s pretty fortunate that we have a special utility
that can monitor compilation
The Second Check
39
40. The Second Analysis Attempt
40
1. Start the compilation monitoring
utility before building the project
2. The utility collects all the required
data
3. Right after that’s done, the analysis
starts
4. ???????
5.
41. 1. Start the compilation monitoring
utility before building the project
2. The utility collects all the required
data
3. Right after that’s done,
the analysis starts
4. ???????
5. EPIC WIN!!!
The Second Analysis Attempt
41
60. 2. Prevent New Errors
60
How to detect new triggerings among old
warnings?
Approach 1: incremental analysis
Approach 2: warning mass suppression (the use
of a suppress base)
61. How to Work with a Suppress Base
61
Hide all old warnings
Get 0 warnings after analysis
Starting from this moment, all new mistakes
will be detected at once
64. How to Work with a Suppress Base
64
Old warnings don’t go anywhere!
We just separated them from the new ones and
work on them separately.
65. Incremental Analysis or a Suppress Base?
65
When dealing with Unreal Engine 4, we used
only incremental analysis
Suppress bases are more convenient if you are
the one developing the project
You can use both approaches simultaneously
66. How to Process Old Errors
66
1. Set up your development process so that it involves
continuous analysis
2. Prevent new errors
3. Process the analyzer’s report gradually, line-by-line,
and save resources.
67. 3. How to Work with a Huge Report
67
Two approaches:
The Pareto principle (80/20)
The ratchet method
69. The Pareto Principle
69
In order to fix 80% of errors, reviewing 20% of
warnings is sufficient
The warnings have already been separated into
these portions and are ready for use
74. The total number of warnings is committed to
the version control system
Changes are allowed only if they do not add to
this number of errors
The Ratchet Method
74
87. If the Warnings Count in Thousands:
87
1.Set up your development process so that it involves
continuous analysis
2.Prevent new mistakes
3.Work through the analyzer’s report gradually
(the Pareto and ratchet principles)