Incorrect string comparison
Incorrect string comparison
It has become a “good tradition” for Microsoft to make their products open-source: CoreFX, .Net Compiler Platform (Roslyn), Code Contracts, MSBuild, and other projects. For us, the developers of PVS-Studio analyzer, it’s an opportunity to check well-known projects, tell people (including the project authors themselves) about the bugs we find, and additionally test our analyzer. Today we are going to talk about the errors found in another project by Microsoft, PowerShell.
The Microsoft company made a present to all programmers eager to dig into some interesting stuff: they opened the source codes of MS-DOS v 1.1, v 2.0 and Word for Windows 1.1a. The MS-DOS operating system is written in an assembler, so the analyzer cannot be applied to it. But Word is written in C. Word 1.1a’s source codes are almost 25 years old, but we still managed to analyze it. There’s no practical use of it, of course. Just for fun.
About a year ago Microsoft made the CoreCLR and CoreFX source code open. The latter project wasn’t of a big interest to us until recently, as it was written in C#, not in C++. But with the release of PVS-Studio 6.00 that now supports C# I decided to go back to the CoreFX and write an article about its analysis.
We have checked the Windows 8 Driver Samples pack with our PVS-Studio analyzer and found various bugs in its samples. There is nothing horrible about it – bugs can be found everywhere, so the title of this article may sound a bit high-flown. But these particular errors may be really dangerous, as it is a usual practice for developers to use demo samples as a basis for their own projects or borrow code fragments from them.
Microsoft have given open access to the source code of a tool kit that is used in the company to speed up the development of artificial intelligence: Computational Network Toolkit is now available at Github. The developers had to create their own custom solution, because the existing tools did not work fast enough.
Let’s have a look at the analysis results of the source code of this project, as done by our static code analyzer.
The Microsoft Corporation has recently published, for free, access the source code of the CoreCLR engine, which is a key component of .NET Core. We couldn’t help but pay attention to this event. The wider a project’s audience is, the worse defects found in the code will seem, won’t they? Despite Microsoft themselves being the authors of the product, there are still some issues to examine and think over in their code – just like in any other large project.
Static code analysis tools can help developers eliminate numbers of bugs as early as at the coding stage. With their help you can, for example, quickly catch and fix any typos. Well, some programmers are sincerely sure they never make typos and silly mistakes. But they are wrong; everyone makes mistakes. This article is a good evidence of that. Typos can be found even in high-quality and well tested projects such as Qt.