SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
Brief analysis of Media Portal 2 bugs
Author: Ivan Kishchenko
Date: 06.03.2017
Media Portal 2 is open software of a media center class, allowing the user to listen to music, watch
videos, viewing pictures, and much more. For us, the developers of PVS-Studio static analyzer, this is
another chance to check an interesting project, tell people (and developers) about the errors we find,
and demonstrate the abilities of our analyzer of course.
About the project Media Portal 2
About the project Media Portal 2T, the project description taken from Wikipedia:
MediaPortal provides a 10-foot user interface for performing typical PVR/TiVo functionality, including
playing, pausing, and recording live TV; playing DVDs, videos, and music; viewing pictures; and other
functions. Plugins allow it to perform additional tasks, such as watching online video, listening to music
from online services such as Last.fm, and launching other applications such as games. It interfaces with
hardware commonly found in HTPCs, such as TV tuners, infrared receivers, and LCD displays.
A large part of the project is written in C#. There are separate units written in C++. Also, as far as I
understand, the Media Portal 2 developers are already using ReSharper in their project. I drew this
conclusion by seeing its mention in the .gitignore file. We do not like the idea of comparing PVS-Studio
and ReSharper, because these are different types of tools. However, as you can see, using ReSharper did
not prevent us from finding real errors in the code.
The analysis results
During the analysis we checked 3321 files. In total, there were 512,435 lines of code. As a result of the
check we had 72 high level warnings. 57 of them pointed to actual errors, typos, issues and strange
fragments in the code. There were also 79 second (medium) level warnings. In my own opinion, 53
warnings pointed to problematic or strange places in the code. We aren't going to look at the lowest
level warnings, because these warnings usually don't indicate real errors, have quite a large number of
false positives, and contain warnings that aren't relevant for most of the projects.
So the analyzer detected 0.2 errors per 1000 lines of code. The percentage of false positives is just 27%,
which is a very good result.
I should say right away that sometimes it's very hard to determine what exactly programmer meant to
achieve when was writing a particular piece of code. That's why those fragments that I considered
erroneous can have some distorted logic, but in the scope of a certain algorithm, can work quite
normally. But if this code is reused in another application, by another person who is unaware of all the
nuances of implementation, then most likely it will lead to bugs in their system.
Also, I want to note that the article doesn't cover all errors, since there are too many of them for a single
article.
So, let's take a look at the most interesting bugs we found; the project authors can do a more detailed
review of the bugs by doing the project check themselves, or by making a request for a temporary
license. Also, dear readers, if you are non-commercial or individual developers, I suggest using the free
version of our static analyzer. Its functional abilities are absolutely identical to the paid version and so, it
is the perfect fit for students, individual developers, and teams of enthusiasts.
Typos when using Copy-Paste
I will start the description with quite widespread errors when a programmer has copied a code block,
but forgot to change one or several variables in it due to inattention.
V3127 Two similar code fragments were found. Perhaps, this is a typo and 'AllocinebId' variable should
be used instead of 'CinePassionId' MovieRelationshipExtractor.cs 126
if (movie.CinePassionId > 0)
ids.Add(ExternalIdentifierAspect.SOURCE_CINEPASSION,
movie.CinePassionId.ToString());
if (movie.CinePassionId > 0) // <=
ids.Add(ExternalIdentifierAspect.SOURCE_ALLOCINE,
movie.AllocinebId.ToString());
It's very hard to find such bugs by doing a simple code review. Since the code is very stuck together,
most likely, the programmer just hasn't noticed the defect. Looking at the line marked with a comment,
you'll notice that the word Allocine is used instead of CinePassion everywhere in the second if block, but
in the condition of the check the variable CinePassionId was not replaced with AllocinebId.
The diagnostic V3217 found several more interesting typos showing the danger of Copy-Paste.
V3127 Two similar code fragments were found. Perhaps, this is a typo and 'Y' variable should be used
instead of 'X' PointAnimation.cs 125
double distx = (to.X - from.X) / duration;
distx *= timepassed;
distx += from.X;
double disty = (to.X - from.Y) / duration; // <=
disty *= timepassed;
disty += from.Y;
V3127 Two similar code fragments were found. Perhaps, this is a typo and 'X' variable should be used
instead of 'Y' Point2DList.cs 935
double dx1 = this[upper].Y - this[middle].X; // <=
double dy1 = this[upper].Y - this[middle].Y;
V3127 Two similar code fragments were found. Perhaps, this is a typo and 'attrY' variable should be
used instead of 'attrX' AbstractSortByComparableValueAttribute.cs 94
if (attrX != null)
{
valX = (T?)aspectX.GetAttributeValue(attrX);
}
if (attrY != null)
{
valX = (T?)aspectX.GetAttributeValue(attrX); // <=
}
In all cases in the first block, the evaluations are with the x axis; in the second block with the Y axis. If we
look at the commented lines, we can see that the programmer forgot to change X to Y or vice versa,
when copy pasting one of the blocks.
Access by null reference
Programming language is continuously evolving, but the main way to shoot yourself in the foot remain
the same. In the example of the code cited below, the programmer first verifies the BannerPath variable
against null. If it is null, then he checks that it is equal to an empty string with an Equals method, which
may cause a potential NullReferenceException.
V3080 Possible null dereference. Consider inspecting 'BannerPath'. TvdbBannerWithThumb.cs 91
if (ThumbPath == null &&
(BannerPath != null || BannerPath.Equals(""))) // <=
{
ThumbPath = String.Concat("_cache/", BannerPath);
}
This code fragment is rather strange, if we take into account the code after the check. To my mind, the
check should be triggered if the variable BannerPath is not null and not an empty string.
Correct variant can be like this:
if (ThumbPath == null &&
!string.IsNullOrEmpty(BannerPath))
{
ThumbPath = String.Concat("_cache/", BannerPath);
}
Incorrect operator precedence
I suggest taking a look at another quite amusing warning related to incorrect precedence of logic
operators.
V3130 Priority of the '&&' operator is higher than that of the '||' operator. Possible missing
parentheses. BinaryCacheProvider.cs 495
return config.EpisodesLoaded || !checkEpisodesLoaded &&
config.BannersLoaded || !checkBannersLoaded &&
config.ActorsLoaded || !checkActorsLoaded;
The programmer who wrote this code apparently did not take into account that the logical AND
operator (&&) has a higher precedence than the logical OR (||) operator. Once more, I would
recommend specifying explicitly the precedence of operations, and putting parentheses between them.
Here is one more error caused by incorrect operator precedence. The programmer ignores the fact that
the + operator has a higher priority than the ?? operator.
V3022 Expression '"Invalid header name: " + name' is always not null. The operator '??' is excessive.
HttpRequest.cs 309
...("Invalid header name: " + name ?? "<null>");
As a result, if the variable name is zero, it will be added to the string "Invalid header name:" as an empty
string, and will not be replaced by the expression "<null>". It's not a very crucial error in and of itself,
and in this case it won't lead to a crash.
The corrected variant will be as follows.
...("Invalid header name: " + (name ?? "<null>"));
A typo after the type casting
One more common typo that is caused by inattention. Note the variables other and obj.
V3019 Possibly an incorrect variable is compared to null after type conversion using 'as' keyword. Check
variables 'obj', 'other'. EpisodeInfo.cs 560
EpisodeInfo other = obj as EpisodeInfo;
if (obj == null) return false; // <=
if (TvdbId > 0 && other.TvdbId > 0)
return TvdbId == other.TvdbId;
....
In this code fragment a variable obj is explicitly cast to the EpisodeInfo type, and the result is returned to
the variable other. Note that further on we see a variable other being used, but the variable obj gets
verified against null. In the case that the variable obj we'll have is a type different from what it is cast to,
then to work with the other variable will lead to an exception.
Here is how a fixed code fragment may look:
EpisodeInfo other = obj as EpisodeInfo;
if (other == null) return false;
if (TvdbId > 0 && other.TvdbId > 0)
return TvdbId == other.TvdbId;
....
Double assignment
One more amusing error that was found by the analyzer. The following code fragment would be
meaningless, because the Released variable will always be equal to null.
V3008 The 'Released' variable is assigned values twice successively. Perhaps this is a mistake. Check
lines: 57, 56. OmDbSeasonEpisode.cs 57
DateTime releaseDate;
if (DateTime.TryParse(value, out releaseDate))
Released = releaseDate; // <=
Released = null; // <=
Most likely this statement with the nullification should be written in the else block. Then the correct
code fragment will be like this:
DateTime releaseDate;
if (DateTime.TryParse(value, out releaseDate))
Released = releaseDate; // <=
else
Released = null; // <=
When a minute doesn't always have 60 seconds
V3118 Milliseconds component of TimeSpan is used, which does not represent full time interval.
Possibly 'TotalMilliseconds' value was intended instead. Default.cs 60
private void WaitForNextFrame()
{
double msToNextFrame = _msPerFrame -
(DateTime.Now - _frameRenderingStartTime).Milliseconds;
if (msToNextFrame > 0)
Thread.Sleep(TimeSpan.FromMilliseconds(msToNextFrame));
}
Another fairly common typo that occurs because of the TimeSpan type implementation. But apparently,
the programmer did not know that the Seconds property of the object of TimeSpan type returns not the
total number of seconds in this interval, but the remaining number of seconds.
For example, if the time interval is 1minute, 150 seconds, then the call of the Milliseconds method will
return only 150 miliseconds. If it is necessary to return a total number of seconds, we should use the
method TotalMilliseconds. For this example it will be 1150 milliseconds.
Then the correct code could be as follows:
double msToNextFrame = _msPerFrame -
(DateTime.Now - _frameRenderingStartTime).TotalMilliseconds;
Incorrect order of arguments
One more mistake caused by inattentiveness. The method TryCreateMultimediaCDDrof iveHandler gets
enumerations of identifiers for videos, pictures, and audio in the specified sequence.
V3066 Possible incorrect order of arguments passed to 'TryCreateMultimediaCDDriveHandler' method.
RemovableMediaManager.cs 109
public static MultimediaDriveHandler
TryCreateMultimediaCDDriveHandler(DriveInfo driveInfo,
IEnumerable<Guid> videoMIATypeIds,
IEnumerable<Guid> imageMIATypeIds, // <=
IEnumerable<Guid> audioMIATypeIds) // <=
{ .... }
Since these parameters have the same types, the programmer didn't pay attention to the fact that when
he was passing arguments to the method, he misplaced pictures and audios:
public static ....()
{
MultimediaDriveHandler.TryCreateMultimediaCDDriveHandler(driveInfo,
Consts.NECESSARY_VIDEO_MIAS,
Consts.NECESSARY_AUDIO_MIAS, // <=
Consts.NECESSARY_IMAGE_MIAS) // <=
}
A condition that is always false
This code is pretty strange, so I was not sure if I should put it here or not.
V3022 Expression 'IsVignetteLoaded' is always false. TvdbFanartBanner.cs 219
if (IsVignetteLoaded) // <=
{
Log.Warn(....);
return false;
}
try
{
if (IsVignetteLoaded) // <=
{
LoadVignette(null);
}
....
I can assume that the first check was added for debugging, and that most likely, the programmer forgot
to remove it. As a result it blocks the second check which can lead to incorrect program execution.
Redundant check or an egregious error?
V3001 There are identical sub-expressions 'screenWidth != _screenSize.Width' to the left and to the
right of the '||' operator. MainForm.cs 922
if (bitDepth != _screenBpp ||
screenWidth != _screenSize.Width ||
screenWidth != _screenSize.Width) // <=
{
....
}
Pay attention to the last check: Most likely, the programmer wanted to check the width and height, but
after Copy-Paste forgot to replace Width with Height in the last check.
The analyzer found one more similar bug:
V3001 There are identical sub-expressions 'p == null' to the left and to the right of the '||' operator.
TriangulationConstraint.cs 141
public static uint CalculateContraintCode(
TriangulationPoint p, TriangulationPoint q)
{
if (p == null || p == null) // <=
{
throw new ArgumentNullException();
}
....
}
Looking at the body of the method more thoroughly, you may notice that the p parameter is verified
against null twice, at the same time the logic of this method presupposes using the q parameter. Most
likely, the right part of the check should contain a check of the q variable instead of p.
A forgotten condition and some more Copy-Paste
As you may have noticed, the biggest part of errors in this article are caused by Copy-paste, the
following bug is no exception.
V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error
presence. Check lines: 452, 462. Scanner.cs 452
if (style == NumberStyles.Integer)
{
int ivalue;
if (int.TryParse(num, out ivalue))
return ivalue;
....
}
else if (style == NumberStyles.Integer) // <=
{
return double.Parse(num);
}
In both checks the variable style is compared with one and the same value in the enumeration. As a
result, the second check will never be executed. If we keep in mind the fact that during the first check
the string is converted to an integer, and in the second check to a floating-point number. I may assume
that the condition of the second check should be as follows:
....
}
else if (style == NumberStyles.Double) // <=
{
return double.Parse(num);
}
Conclusion
There were many more errors, typos, and issues found in this project. But they didn't seem interesting
enough to describe in this article. In general, I can say that the codebase of the project is not very
readable, and contains a lot of strange fragments. The majority weren't cited in the article, but I would
still consider them bad coding style. This could include using a foreach loop, to get the first element of
the collection and exit using the break at the end of the first iteration, numerous redundant checks,
large unseperated blocks of code, etc.
The Media Portal 2 developers can easily find all the issues, using the PVS-Studio tool. You may also find
bugs in your projects with the help of the mentioned tool.
I would like to mention that the biggest benefit from static analysis, is gained by regular use. It's not
enough to download the tool, and do a one-time check. As an analogy, programmers regularly review
the compiler warnings, not just 3 times a year before release. If the analyzer is used on a regular basis, it
will save significant time that is usually spent on searching for typos and errors.

Contenu connexe

Tendances

Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerAndrey Karpov
 
We Continue Exploring Tizen: C# Components Proved to be of High Quality
We Continue Exploring Tizen: C# Components Proved to be of High QualityWe Continue Exploring Tizen: C# Components Proved to be of High Quality
We Continue Exploring Tizen: C# Components Proved to be of High QualityPVS-Studio
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...PVS-Studio
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Andrey Karpov
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLitePVS-Studio
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggyPVS-Studio
 
Sony C#/.NET component set analysis
Sony C#/.NET component set analysisSony C#/.NET component set analysis
Sony C#/.NET component set analysisPVS-Studio
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioAndrey Karpov
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportPVS-Studio
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectPVS-Studio
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...PVS-Studio
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxPVS-Studio
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project AnalyzedPVS-Studio
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioPVS-Studio
 
Checking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverChecking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverPVS-Studio
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggyAndrey Karpov
 
Checking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioChecking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioPVS-Studio
 
Cppcheck and PVS-Studio compared
Cppcheck and PVS-Studio comparedCppcheck and PVS-Studio compared
Cppcheck and PVS-Studio comparedPVS-Studio
 
A Post About Analyzing PHP
A Post About Analyzing PHPA Post About Analyzing PHP
A Post About Analyzing PHPAndrey Karpov
 

Tendances (20)

Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
 
We Continue Exploring Tizen: C# Components Proved to be of High Quality
We Continue Exploring Tizen: C# Components Proved to be of High QualityWe Continue Exploring Tizen: C# Components Proved to be of High Quality
We Continue Exploring Tizen: C# Components Proved to be of High Quality
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLite
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
 
Sony C#/.NET component set analysis
Sony C#/.NET component set analysisSony C#/.NET component set analysis
Sony C#/.NET component set analysis
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-Studio
 
Re-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large reportRe-checking the ReactOS project - a large report
Re-checking the ReactOS project - a large report
 
Dusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind projectDusting the globe: analysis of NASA World Wind project
Dusting the globe: analysis of NASA World Wind project
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBox
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-Studio
 
Checking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source serverChecking the World of Warcraft CMaNGOS open source server
Checking the World of Warcraft CMaNGOS open source server
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
 
Checking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioChecking OpenCV with PVS-Studio
Checking OpenCV with PVS-Studio
 
Cppcheck and PVS-Studio compared
Cppcheck and PVS-Studio comparedCppcheck and PVS-Studio compared
Cppcheck and PVS-Studio compared
 
A Post About Analyzing PHP
A Post About Analyzing PHPA Post About Analyzing PHP
A Post About Analyzing PHP
 

Similaire à Brief analysis of Media Portal 2 bugs

Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindAccord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindPVS-Studio
 
LibRaw, Coverity SCAN, PVS-Studio
LibRaw, Coverity SCAN, PVS-StudioLibRaw, Coverity SCAN, PVS-Studio
LibRaw, Coverity SCAN, PVS-StudioAndrey Karpov
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...PVS-Studio
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio
 
Analysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodePVS-Studio
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Andrey Karpov
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopPVS-Studio
 
Long-Awaited Check of CryEngine V
Long-Awaited Check of CryEngine VLong-Awaited Check of CryEngine V
Long-Awaited Check of CryEngine VPVS-Studio
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedPVS-Studio
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That CouldPVS-Studio
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codeAndrey Karpov
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer ReviewAndrey Karpov
 
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioAnalysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioPVS-Studio
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedAndrey Karpov
 
Bugs found in GCC with the help of PVS-Studio
Bugs found in GCC with the help of PVS-StudioBugs found in GCC with the help of PVS-Studio
Bugs found in GCC with the help of PVS-StudioPVS-Studio
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1PVS-Studio
 

Similaire à Brief analysis of Media Portal 2 bugs (18)

Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindAccord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
 
LibRaw, Coverity SCAN, PVS-Studio
LibRaw, Coverity SCAN, PVS-StudioLibRaw, Coverity SCAN, PVS-Studio
LibRaw, Coverity SCAN, PVS-Studio
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
Analysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source Code
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelop
 
Checking VirtualDub
Checking VirtualDubChecking VirtualDub
Checking VirtualDub
 
Long-Awaited Check of CryEngine V
Long-Awaited Check of CryEngine VLong-Awaited Check of CryEngine V
Long-Awaited Check of CryEngine V
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checked
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That Could
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer Review
 
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-StudioAnalysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not used
 
Bugs found in GCC with the help of PVS-Studio
Bugs found in GCC with the help of PVS-StudioBugs found in GCC with the help of PVS-Studio
Bugs found in GCC with the help of PVS-Studio
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
 

Dernier

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Dernier (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Brief analysis of Media Portal 2 bugs

  • 1. Brief analysis of Media Portal 2 bugs Author: Ivan Kishchenko Date: 06.03.2017 Media Portal 2 is open software of a media center class, allowing the user to listen to music, watch videos, viewing pictures, and much more. For us, the developers of PVS-Studio static analyzer, this is another chance to check an interesting project, tell people (and developers) about the errors we find, and demonstrate the abilities of our analyzer of course. About the project Media Portal 2 About the project Media Portal 2T, the project description taken from Wikipedia: MediaPortal provides a 10-foot user interface for performing typical PVR/TiVo functionality, including playing, pausing, and recording live TV; playing DVDs, videos, and music; viewing pictures; and other functions. Plugins allow it to perform additional tasks, such as watching online video, listening to music from online services such as Last.fm, and launching other applications such as games. It interfaces with hardware commonly found in HTPCs, such as TV tuners, infrared receivers, and LCD displays. A large part of the project is written in C#. There are separate units written in C++. Also, as far as I understand, the Media Portal 2 developers are already using ReSharper in their project. I drew this conclusion by seeing its mention in the .gitignore file. We do not like the idea of comparing PVS-Studio and ReSharper, because these are different types of tools. However, as you can see, using ReSharper did not prevent us from finding real errors in the code. The analysis results During the analysis we checked 3321 files. In total, there were 512,435 lines of code. As a result of the check we had 72 high level warnings. 57 of them pointed to actual errors, typos, issues and strange fragments in the code. There were also 79 second (medium) level warnings. In my own opinion, 53
  • 2. warnings pointed to problematic or strange places in the code. We aren't going to look at the lowest level warnings, because these warnings usually don't indicate real errors, have quite a large number of false positives, and contain warnings that aren't relevant for most of the projects. So the analyzer detected 0.2 errors per 1000 lines of code. The percentage of false positives is just 27%, which is a very good result. I should say right away that sometimes it's very hard to determine what exactly programmer meant to achieve when was writing a particular piece of code. That's why those fragments that I considered erroneous can have some distorted logic, but in the scope of a certain algorithm, can work quite normally. But if this code is reused in another application, by another person who is unaware of all the nuances of implementation, then most likely it will lead to bugs in their system. Also, I want to note that the article doesn't cover all errors, since there are too many of them for a single article. So, let's take a look at the most interesting bugs we found; the project authors can do a more detailed review of the bugs by doing the project check themselves, or by making a request for a temporary license. Also, dear readers, if you are non-commercial or individual developers, I suggest using the free version of our static analyzer. Its functional abilities are absolutely identical to the paid version and so, it is the perfect fit for students, individual developers, and teams of enthusiasts.
  • 3. Typos when using Copy-Paste I will start the description with quite widespread errors when a programmer has copied a code block, but forgot to change one or several variables in it due to inattention. V3127 Two similar code fragments were found. Perhaps, this is a typo and 'AllocinebId' variable should be used instead of 'CinePassionId' MovieRelationshipExtractor.cs 126 if (movie.CinePassionId > 0) ids.Add(ExternalIdentifierAspect.SOURCE_CINEPASSION, movie.CinePassionId.ToString()); if (movie.CinePassionId > 0) // <= ids.Add(ExternalIdentifierAspect.SOURCE_ALLOCINE, movie.AllocinebId.ToString()); It's very hard to find such bugs by doing a simple code review. Since the code is very stuck together, most likely, the programmer just hasn't noticed the defect. Looking at the line marked with a comment, you'll notice that the word Allocine is used instead of CinePassion everywhere in the second if block, but in the condition of the check the variable CinePassionId was not replaced with AllocinebId. The diagnostic V3217 found several more interesting typos showing the danger of Copy-Paste. V3127 Two similar code fragments were found. Perhaps, this is a typo and 'Y' variable should be used instead of 'X' PointAnimation.cs 125 double distx = (to.X - from.X) / duration; distx *= timepassed; distx += from.X; double disty = (to.X - from.Y) / duration; // <= disty *= timepassed; disty += from.Y; V3127 Two similar code fragments were found. Perhaps, this is a typo and 'X' variable should be used instead of 'Y' Point2DList.cs 935 double dx1 = this[upper].Y - this[middle].X; // <= double dy1 = this[upper].Y - this[middle].Y; V3127 Two similar code fragments were found. Perhaps, this is a typo and 'attrY' variable should be used instead of 'attrX' AbstractSortByComparableValueAttribute.cs 94
  • 4. if (attrX != null) { valX = (T?)aspectX.GetAttributeValue(attrX); } if (attrY != null) { valX = (T?)aspectX.GetAttributeValue(attrX); // <= } In all cases in the first block, the evaluations are with the x axis; in the second block with the Y axis. If we look at the commented lines, we can see that the programmer forgot to change X to Y or vice versa, when copy pasting one of the blocks. Access by null reference Programming language is continuously evolving, but the main way to shoot yourself in the foot remain the same. In the example of the code cited below, the programmer first verifies the BannerPath variable against null. If it is null, then he checks that it is equal to an empty string with an Equals method, which may cause a potential NullReferenceException. V3080 Possible null dereference. Consider inspecting 'BannerPath'. TvdbBannerWithThumb.cs 91 if (ThumbPath == null && (BannerPath != null || BannerPath.Equals(""))) // <= { ThumbPath = String.Concat("_cache/", BannerPath); } This code fragment is rather strange, if we take into account the code after the check. To my mind, the check should be triggered if the variable BannerPath is not null and not an empty string. Correct variant can be like this: if (ThumbPath == null && !string.IsNullOrEmpty(BannerPath)) { ThumbPath = String.Concat("_cache/", BannerPath); } Incorrect operator precedence I suggest taking a look at another quite amusing warning related to incorrect precedence of logic operators. V3130 Priority of the '&&' operator is higher than that of the '||' operator. Possible missing parentheses. BinaryCacheProvider.cs 495 return config.EpisodesLoaded || !checkEpisodesLoaded && config.BannersLoaded || !checkBannersLoaded &&
  • 5. config.ActorsLoaded || !checkActorsLoaded; The programmer who wrote this code apparently did not take into account that the logical AND operator (&&) has a higher precedence than the logical OR (||) operator. Once more, I would recommend specifying explicitly the precedence of operations, and putting parentheses between them. Here is one more error caused by incorrect operator precedence. The programmer ignores the fact that the + operator has a higher priority than the ?? operator. V3022 Expression '"Invalid header name: " + name' is always not null. The operator '??' is excessive. HttpRequest.cs 309 ...("Invalid header name: " + name ?? "<null>"); As a result, if the variable name is zero, it will be added to the string "Invalid header name:" as an empty string, and will not be replaced by the expression "<null>". It's not a very crucial error in and of itself, and in this case it won't lead to a crash. The corrected variant will be as follows. ...("Invalid header name: " + (name ?? "<null>")); A typo after the type casting One more common typo that is caused by inattention. Note the variables other and obj. V3019 Possibly an incorrect variable is compared to null after type conversion using 'as' keyword. Check variables 'obj', 'other'. EpisodeInfo.cs 560 EpisodeInfo other = obj as EpisodeInfo; if (obj == null) return false; // <= if (TvdbId > 0 && other.TvdbId > 0) return TvdbId == other.TvdbId; .... In this code fragment a variable obj is explicitly cast to the EpisodeInfo type, and the result is returned to the variable other. Note that further on we see a variable other being used, but the variable obj gets verified against null. In the case that the variable obj we'll have is a type different from what it is cast to, then to work with the other variable will lead to an exception. Here is how a fixed code fragment may look: EpisodeInfo other = obj as EpisodeInfo; if (other == null) return false; if (TvdbId > 0 && other.TvdbId > 0) return TvdbId == other.TvdbId; .... Double assignment One more amusing error that was found by the analyzer. The following code fragment would be meaningless, because the Released variable will always be equal to null. V3008 The 'Released' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 57, 56. OmDbSeasonEpisode.cs 57 DateTime releaseDate; if (DateTime.TryParse(value, out releaseDate)) Released = releaseDate; // <= Released = null; // <=
  • 6. Most likely this statement with the nullification should be written in the else block. Then the correct code fragment will be like this: DateTime releaseDate; if (DateTime.TryParse(value, out releaseDate)) Released = releaseDate; // <= else Released = null; // <= When a minute doesn't always have 60 seconds V3118 Milliseconds component of TimeSpan is used, which does not represent full time interval. Possibly 'TotalMilliseconds' value was intended instead. Default.cs 60 private void WaitForNextFrame() { double msToNextFrame = _msPerFrame - (DateTime.Now - _frameRenderingStartTime).Milliseconds; if (msToNextFrame > 0) Thread.Sleep(TimeSpan.FromMilliseconds(msToNextFrame)); } Another fairly common typo that occurs because of the TimeSpan type implementation. But apparently, the programmer did not know that the Seconds property of the object of TimeSpan type returns not the total number of seconds in this interval, but the remaining number of seconds. For example, if the time interval is 1minute, 150 seconds, then the call of the Milliseconds method will return only 150 miliseconds. If it is necessary to return a total number of seconds, we should use the method TotalMilliseconds. For this example it will be 1150 milliseconds. Then the correct code could be as follows: double msToNextFrame = _msPerFrame - (DateTime.Now - _frameRenderingStartTime).TotalMilliseconds; Incorrect order of arguments One more mistake caused by inattentiveness. The method TryCreateMultimediaCDDrof iveHandler gets enumerations of identifiers for videos, pictures, and audio in the specified sequence. V3066 Possible incorrect order of arguments passed to 'TryCreateMultimediaCDDriveHandler' method. RemovableMediaManager.cs 109 public static MultimediaDriveHandler TryCreateMultimediaCDDriveHandler(DriveInfo driveInfo, IEnumerable<Guid> videoMIATypeIds, IEnumerable<Guid> imageMIATypeIds, // <= IEnumerable<Guid> audioMIATypeIds) // <= { .... }
  • 7. Since these parameters have the same types, the programmer didn't pay attention to the fact that when he was passing arguments to the method, he misplaced pictures and audios: public static ....() { MultimediaDriveHandler.TryCreateMultimediaCDDriveHandler(driveInfo, Consts.NECESSARY_VIDEO_MIAS, Consts.NECESSARY_AUDIO_MIAS, // <= Consts.NECESSARY_IMAGE_MIAS) // <= } A condition that is always false This code is pretty strange, so I was not sure if I should put it here or not. V3022 Expression 'IsVignetteLoaded' is always false. TvdbFanartBanner.cs 219 if (IsVignetteLoaded) // <= { Log.Warn(....); return false; } try { if (IsVignetteLoaded) // <= { LoadVignette(null); } .... I can assume that the first check was added for debugging, and that most likely, the programmer forgot to remove it. As a result it blocks the second check which can lead to incorrect program execution. Redundant check or an egregious error? V3001 There are identical sub-expressions 'screenWidth != _screenSize.Width' to the left and to the right of the '||' operator. MainForm.cs 922 if (bitDepth != _screenBpp || screenWidth != _screenSize.Width || screenWidth != _screenSize.Width) // <= { .... } Pay attention to the last check: Most likely, the programmer wanted to check the width and height, but after Copy-Paste forgot to replace Width with Height in the last check. The analyzer found one more similar bug: V3001 There are identical sub-expressions 'p == null' to the left and to the right of the '||' operator. TriangulationConstraint.cs 141 public static uint CalculateContraintCode( TriangulationPoint p, TriangulationPoint q) { if (p == null || p == null) // <= { throw new ArgumentNullException();
  • 8. } .... } Looking at the body of the method more thoroughly, you may notice that the p parameter is verified against null twice, at the same time the logic of this method presupposes using the q parameter. Most likely, the right part of the check should contain a check of the q variable instead of p. A forgotten condition and some more Copy-Paste As you may have noticed, the biggest part of errors in this article are caused by Copy-paste, the following bug is no exception. V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 452, 462. Scanner.cs 452 if (style == NumberStyles.Integer) { int ivalue; if (int.TryParse(num, out ivalue)) return ivalue; .... } else if (style == NumberStyles.Integer) // <= { return double.Parse(num); } In both checks the variable style is compared with one and the same value in the enumeration. As a result, the second check will never be executed. If we keep in mind the fact that during the first check the string is converted to an integer, and in the second check to a floating-point number. I may assume that the condition of the second check should be as follows: .... } else if (style == NumberStyles.Double) // <= { return double.Parse(num); } Conclusion
  • 9. There were many more errors, typos, and issues found in this project. But they didn't seem interesting enough to describe in this article. In general, I can say that the codebase of the project is not very readable, and contains a lot of strange fragments. The majority weren't cited in the article, but I would still consider them bad coding style. This could include using a foreach loop, to get the first element of the collection and exit using the break at the end of the first iteration, numerous redundant checks, large unseperated blocks of code, etc. The Media Portal 2 developers can easily find all the issues, using the PVS-Studio tool. You may also find bugs in your projects with the help of the mentioned tool. I would like to mention that the biggest benefit from static analysis, is gained by regular use. It's not enough to download the tool, and do a one-time check. As an analogy, programmers regularly review the compiler warnings, not just 3 times a year before release. If the analyzer is used on a regular basis, it will save significant time that is usually spent on searching for typos and errors.