Getting Acquainted with the PVS-Studio Static Code Analyzer
- Pros of using a static analyzer
- PVS-Studio's capabilities
PVS-Studio is a static analyzer for C/C++/C# code designed to assist programmers in searching for and fixing a number of software errors of different patterns. The analyzer integrates into Visual Studio as a plugin, providing a convenient user interface for easy code navigation and error search. There is also a Standalone version available which is used independently of Visual Studio and allows analyzing files compiled with, besides Visual C++, such compilers as Embarcadero C++Builder, GCC (MinGW), and Clang.
A static analyzer does not substitute other bug searching tools - it just complements them. Integrating a static analysis tool with the development process helps to eliminate plenty of errors at the moment when they are only "born", thus saving your time and resources on their subsequent elimination. As everyone knows, the earlier a bug is found, the easier it is to fix it. What follows from this is the idea that a static analyzer should be used regularly, for it is the only best way to get most of it.
PVS-Studio provides 3 warning levels, the 1-st level dealing with the most critical issues and the 3-rd with insignificant faults in the code or warnings which are very likely to be false positives. Warning level switch buttons allow sorting the messages according to the user's current needs.
There are 3 types of diagnostic rules: general analysis diagnostics (GA), diagnostics for microoptimizations (OP), and 64-bit diagnostics (64). Switching a certain diagnostic rule set shows or hides the corresponding messages.
Figure 1 - Message output window (click on the image to enlarge it)
The tool provides an option to filter messages by a number of different criteria. Also, you can completely turn off the displaying of certain messages, which may be useful at times.
When installing PVS-Studio, you can choose which versions of the Microsoft Visual Studio IDE the analyzer should integrate with.
After deciding on all the necessary options and completing the setup, PVS-Studio will integrate into the IDE's menu. In Figure 2, you can see that the corresponding command has appeared in Visual Studio's menu, as well as the message output window.
Figure 2 - Microsoft Visual Studio's appearance after PVS-Studio's integration (click on the image to enlarge it)
In the settings menu, you can customize PVS-Studio as you need to make it most convenient to work with. For example, it provides the following options:
- Preprocessor selection;
- Exclusion of files and folders from analysis;
- Selection of the diagnostic message types to be displayed during the analysis;
- Plenty of other settings.
Most likely, you won't need any of those at your first encounter with PVS-Studio, but later, they will help you optimize your work with the tool.
To learn more about specifics of PVS-Studio's work when integrated into Microsoft Visual Studio, see the article PVS-Studio for Visual C++.
PVS-Studio can be used independently of the Microsoft Visual Studio IDE. The Standalone version allows analyzing projects while building them. It also supports code navigation through clicking on the diagnostic messages, and search for code fragments and definitions of macros and data types. To learn more about how to work with the Standalone version, see the article Standalone.
Figure 3 - Standalone's start page (click on the image to enlarge it)
PVS-Studio provides an extensive help system on its diagnostic messages. This message database is accessible both from PVS-Studio's interface and at the official site. The message descriptions are accompanied by code samples with error examples, the error description, and available fixing solutions.
To open a diagnostic description, just click with the left mouse button on the diagnostic number in the message output window. These numbers are implemented as hyperlinks.
Technical support for PVS-Studio is carried out via e-mail. Since our technical support is delivered by the tool developers themselves, our users can promptly get responses to a wide variety of questions.