PVS-Studio: 2 features for a quick start

Sergey Vasiliev
3 min readDec 8, 2022

In this note I’ll share with you some tips on how to easily start using PVS-Studio. Let’s explore these two use cases: when you try the analyzer for the first time and when you integrate it into your project.

Trying PVS-Studio for the first time? View the most interesting warnings

So, what do I expect when running the analyzer on a project for the first time? Primarily, I expect the analyzer to detect some interesting errors. However, there can be two extremes:

  • The analyzer found nothing.
  • The analyzer issued too many warnings.

Let’s take a look at both of these cases.

#1. You have enabled all necessary diagnostics and the analysis has completed successfully, but PVS-Studio still finds nothing? This is a good case, but it’s worth noting that a single check is usually not enough.

Try to run a project analysis regularly for a period of time. As the result, the analyzer will be able to detect the issues that the team has not yet found and fixed. This way you can fully evaluate the tool’s value.

I recommend you find out more on this topic in this brief note.

#2. Let’s imagine a situation when the analyzer issues dozens, or even thousands of warnings. If only we could view just the interesting ones… The solution is the “Best warnings” filter. I’ll explain it in a few words.

The “Best warnings” filter selects the most interesting warnings among all the other ones: these warnings should be diverse and report real errors in code.

You can enable this filter with a simple click, and immediately view a selection of the most interesting warnings. There are no more than 10 of them there.

The “Best warnings” filter is available in the “C and C++ Compiler Monitoring UI” tool, as well as in PVS-Studio plugins for:

  • Visual Studio;
  • Rider;
  • CLion;
  • IntelliJ IDEA.

We collected more information about “Best Warnings” in the documentation.

Integrating the analyzer into the project? Disable warnings for legacy code

I decided to integrate PVS-Studio in an old project with a large amount of legacy code. I ran the analyzer and got hundreds of warnings. What’s next? How can my team spot a new warning and correct an error if the total number of warnings changes from 673 to 674? The answer is — suppress warnings for legacy code.

The action algorithm is the following:

  • Hide all current warnings to make them a technical debt. Now the analyzer issues 0 warnings.
  • Monitor the new analyzer warnings. Fix them as soon as they appear. This way we control the quality and security of the code.

Use the baselining mechanism to suppress warnings for legacy code.

Summary

Making it easy to use PVS-Studio:

  • if you try the analyzer for the first time, see the most interesting warnings. The “Best warnings” filter will help you (documentation);
  • if you integrate PVS-Studio into the development process, disable warnings for legacy code. The baselining mechanism will help you (documentation).

I also recommend looking through this article. It answers many questions related to the analyzer’s first start.

You can download the latest version of PVS-Studio here.

--

--