Questions tagged [pvs-studio]

PVS-Studio is a tool for detecting bugs and security weaknesses in the source code of programs, written in C, C++, C# and Java. It works in Windows, Linux and macOS environment.

PVS-Studio performs static code analysis and generates a report that helps a programmer find and fix bugs. PVS-Studio performs a wide range of code checks, it is also useful to search for misprints and Copy-Paste errors. Examples of such errors: V501, V517, V522, V523, V3001.

The main value of static analysis is in its regular use, so that errors are identified and fixed at the earliest stages. There is no point in wasting 50 hours looking for a bug that could be found with static analysis. So, let's point out that again - the main idea of static analysis is not to find one hidden bug on the day before the release, but to fix dozens of bugs day by day.

The analyzer can be run at night on the server and warn about suspicious code fragments. Ideally, these errors can be detected and fixed before getting into the repository. PVS-Studio can automatically be launched immediately after the compiler for the files that have been just modified. It works in Windows, Linux and macOS environment.

Quick start

PVS-Studio can integrate into Visual Studio development environment 2010-2017. If you use this IDE, then most likely you will just have to go to the menu of PVS-Studio plugin and choose "Check Current Project".

Often, it can be a more complicated process, and you will need to integrate PVS-Studio into a build system, even an exotic one. The topic of integration is too broad to describe it here. You can find all the information in the detailed documentation.

One more point to notice - PVS-Studio for Windows and Linux has special utilities, gathering information about the compiler launches. These tools allow doing a quick analysis of a project that gets compiled in any possible way. You can quickly try out the analyzer abilities, without wasting time on its integration with makefile or a build script. See the description of the utility Standalone (Windows) and pvs-studio-analyzer (Linux/macOS).

Official Q&A platform for free PVS-Studio version

As described in this post, PVS-Studio uses StackOverflow (with the pvs-studio tag) as the official Q&A platform for users of a free PVS-Studio version. Of course, the usual StackOverflow rules still apply. Bug reports and feature requests are not on-topic here on Stack Overflow.

Supported languages and compilers

  • Windows. Visual Studio 2010-2017 C, C++, C++/CLI, C++/CX (WinRT), C#
  • Windows. IAR Embedded Workbench, C/C++ Compiler for ARM C, C++
  • Windows/Linux. Keil µVision, DS-MDK, ARM Compiler 5/6 C, C++
  • Windows/Linux. Texas Instruments Code Composer Studio, ARM Code Generation Tools C, C++
  • Windows/Linux/macOS. GNU Arm Embedded Toolchain, Arm Embedded GCC compiler, C, C++
  • Windows/Linux/macOS. Clang C, C++
  • Linux/macOS. GCC C, C++
  • Windows. MinGW C, C++
  • Windows/Linux/macOS. Java

Additional links:

63 questions
25
votes
4 answers

Expression 'i < 0' is always false

For the following snippet: size_t i = 0; std::wstring s; s = (i < 0) ? L"ABC" : L"DEF"; s = (i != -1) ? L"ABC" : L"DEF"; PVS-Studio analysis logs warning for the first condition i < 0, as expected: V547 Expression 'i < 0' is always false.…
mloskot
  • 37,086
  • 11
  • 109
  • 136
5
votes
1 answer

Dealing with unsigned integers

I know that unsigned integers are infamous and generally avoided by C++ devs. I have a class with two int member variables that should not contain negative values: . . . private: int m_Y_AxisLen; int m_X_AxisLen; . . . I have designed the…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
5
votes
3 answers

Dangerous magic number N used

PVS-Studio, the static code analyzer, for the following bit of code size_t const n = 4; int a[n] = {}; reports: V112 Dangerous magic number 4 used: ...t const n = 4;. test.cpp 3 Although PVS-Studio is used with Visual Studio 2017 project and…
mloskot
  • 37,086
  • 11
  • 109
  • 136
4
votes
1 answer

Error on startup when not having c++ installed

I'm seeing this error in the activity log when starting up VS 15.3.1. It seems to be related to PVS studio, as it goes away when I disable the extension. I'm only using C#, so I don't have any c++ modules installed. After clicking OK to the message,…
Jonas Nyrup
  • 2,376
  • 18
  • 25
3
votes
1 answer

PVS studio compare with sonarqube

I recently came across PVS Studio. I would like to know how PVS Studio is different from SonarQube. I see that, both tools perform static code analysis. I am trying to understand which is the best tool to opt for. Any insights are helpful. Best…
Gowtham
  • 127
  • 1
  • 6
3
votes
2 answers

Why do some static analysis tools not report potential buffer overflows?

I have an example of a strcpy command that seems to be a risk of a buffer overflow, but PVS-Studio doesn’t raise a warning. In my example, strcpy is used to copy a command line argument into a buffer, without checking the size of the command line…
Sam Johnson
  • 973
  • 9
  • 21
2
votes
1 answer

Can "unspecified order of evaluation" be detected with static analysis?

For most of my C++ projects, I strongly rely on static analysis to prevent bugprone code getting into the master branch. However, nothing seems to detect bugs caused by unspecified order of evaluation. While some tools may spot suspicious code like…
2
votes
1 answer

How can I tell PVS-Studio to ignore all of the files in a third party library when using CMake on Linux

I am using PVS-Studio with CMake on Linux. I recently added a third party library to my project. PVS-Studio is flagging possible issues in the header files for the third party library. How do I go about telling PVS-Studio to ignore the entire third…
David
  • 73
  • 8
2
votes
2 answers

Mark variable as not NULL after BOOST_REQUIRE in PVS-Studio

I'm using PVS-Studio to analyze my Testcode. There are often constructs of the form const noAnimal* animal = dynamic_cast(...); BOOST_REQUIRE(animal); BOOST_REQUIRE_EQUAL(animal->GetSpecies(), ...); However I still get a warning V522…
Flamefire
  • 5,313
  • 3
  • 35
  • 70
2
votes
1 answer

Possible values for -a option in pvs-studio-analyzer

Which values allowed for -a option? Documentation hasn't enough info. It says only: -a MODE, --analysis-mode MODE (default: 4)       MODE defines the type of warnings. 4 - General Analysis. I tried to look up on pvs site. But found nothing.
Ivan Romanov
  • 1,138
  • 1
  • 9
  • 24
2
votes
1 answer

PVS-Studio creates temporary files in the project folder

After each run, PVS-Studio creates a .cpp.PVS-Studio.cfg-file for each checked cpp file right in the project folder. And it doesn't delete them after check is done. It's kinda annoying to delete them by hand or by git checkout. Can PVS-Studio be…
Amomum
  • 6,217
  • 8
  • 34
  • 62
2
votes
1 answer

Failed to obtain a compiler version

I use Microsoft Visual Studio 2015 Community Update 3 to program various software and wanted to check PVS-Studio 6.14.21489 with the free license. But I can't get it to work from Visual Studio, all it's able to outpout is: Failed to preprocess file…
S. Vulton
  • 23
  • 2
1
vote
2 answers

Running PVS-Studio on a C# project on Linux gives weird output file format

The analysis of my C# project outputs a file in an (to me) unknown file format. I would like to convert the output of the analysis to fullhtml with plog-converter, but this tool does not understand the generated analysis output. The output looks…
armset
  • 58
  • 5
1
vote
2 answers

Passing the const-qualified object to the 'std::move'

By doing some code analysis in PVS-Studio, it gave me some warning messages. I have the following statement in a header file: constexpr int MIN_ALLOWED_Y { 0 }; And in a source file: std::make_pair( std::move( MIN_ALLOWED_Y ),…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
1
vote
1 answer

Why is PVS-Studio asking for a license file on Linux (use PVS-Studio for free, individual developer)?

I am trying to analyze a project on Linux using PVS-Studio. I have added the necessary disclaimers to the top of all source files as described here: https://www.viva64.com/en/b/0457/#ID16F8E8F09A (How to use PVS-Studio for Free) // This is an…
David
  • 73
  • 8
1
2 3 4 5