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.
57
questions
5
votes
1
answer
188
views
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;
...
1
vote
2
answers
88
views
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&...
0
votes
2
answers
234
views
PVS-Studio: No compilation units were found
I'm using PVS-Studio in docker image based on ubuntu:18.04 for cross-compiling a couple of files with arm-none-eabi-gcc. After doing pvs-studio-analyzer trace -- .test/compile_with_gcc.sh strace_out ...
1
vote
1
answer
940
views
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 ...
0
votes
1
answer
184
views
PVS Studio analysis
I have a project at university where i need to make a static analysis on a project using any tool .
I chose this project written in C++: https://github.com/AndreaOrru/LaiNES and PVS Studio tool (on ...
0
votes
1
answer
47
views
CLMonitor exit codes
Unfortunately, documentation doesn't mention if CLMonitor utility exits with different codes (for example, to distinguish if errors were found after analysis or weren't).
Can anybody provide list of ...
0
votes
1
answer
92
views
PVS Studio: Suppress V677 from cross-compiler system libraries
I'm compiling a project for Cortex-M processor, which has compiler-specific libraries for standard types. When I analyze the project with PVS-Studio, any real positives get drowned under
/opt/local/...
0
votes
1
answer
172
views
PVS Studio on Linux - command line return codes
Official documentation for Windows command line is quite clear - return code is a bit mask, every bit means something and, particularly, code '256' means 'some issues were found in the source code'.
...
0
votes
2
answers
31
views
Print colored log of PVS-Studio analysis in Linux terminal
I'm trying to integrate PVS-Studio analysis into CI for my homework. Everything seems to work fine except log printing; I want warnings to be colored or highlighted in some other way.
The best I ...
1
vote
1
answer
270
views
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 ...
1
vote
2
answers
210
views
Can I use PVS-Studio to analyze an open-source project which I'm not part of?
From the following blog post:
Note that this mode is not intended to evaluate this software. Please
use a demo version or request a temporary license key to try out the
analyzer.
Do I ...
0
votes
0
answers
24
views
Why PVS-Studio states that there is a non-constant reference? [duplicate]
I must first admit that I have very little experience with C++, so please forgive me if the question looks somewhat stupid.
I've found a puzzling element while analyzing project with PVS-Studio. Here'...
1
vote
1
answer
189
views
PVS Studio Suppress Single Warning For Entire C# File
I am trying to suppress a warning for an entire C# file using syntax found at https://www.viva64.com/en/m/0017/.
According to the documentation //-V::3085 at the beginning of a file should suppress ...
0
votes
1
answer
169
views
How to run .NET Core project with PVS-Studio without Visual Studio?
I have the free license for PVS-Studio and I installed the program to Windows 10 computer without issues. I gave the registration info via Standalone.exe and registration went OK. This computer doesn'...
0
votes
1
answer
303
views
Integrating PVS-Studio and CMake
I use Windows 10, QtCreator 4.7.1, CMake 3.11.4 (Ninja, CodeBlocks), MSVC 2017. Try to integrate PVS-Studio to CMake project.
cmake_minimum_required(VERSION 3.10)
project(tst CXX)
add_executable(${...
1
vote
1
answer
252
views
How to run PVS Studio from command line from Windows 7?
I'm new to PVS Studio. I've installed it in Standalone mode (without Visual Studio). I would like to run PVS Studio from command line (from Cygwin64 Terminal) from Windows 7 Professional 64-bit. I ...
-3
votes
1
answer
124
views
V3022 False Positive
PVS Studio throws V3022: Expression 'list.Count > 1' is always false. Program.cs 20
public class Program
{
private static void Main()
{
var list = new List<string>();
...
0
votes
1
answer
41
views
V3137 False Positive
PVS Studio throws V3137: The 'funclist' variable is assigned but is not used until the end of the function. Program.cs 13
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
...
0
votes
1
answer
44
views
V3125 False Positive
PVS Studio throws V3125: The 'control.Parent' object was used after it was verified against null. Check lines: 11, 9.
using System.Windows.Forms;
namespace V3125_False_Positive
{
static class ...
0
votes
1
answer
72
views
PVS-Studio fails to analyse https://github.com/viva64/pvs-studio-cmake-examples/tree/master/example-1
I pulled down example-1 and generated a CMake project for it using:
cmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DCMAKE_BUILD_TYPE=Debug <source-dir>
When I built the project ...
0
votes
1
answer
117
views
Does PVS-Studio know about forward declaration necessity?
There is a problem when different compilers behave differently. Pity, PVS doesn't tell me about the following dangerous situation.
I have some overloaded functions but I forget to write a forward ...
1
vote
1
answer
294
views
PVS-Studio on Linux - pvs_studio_add_target
I'm trying to use the command pvs_studio_add_target to integrate PVS-Studio into my CMake project. Can anybody point me to an example CMakeLists.txt file that does this?
When I build my project I see ...
1
vote
1
answer
269
views
Does PVS-Studio know about Unicode chars?
This code produces Medium warnings at lines w/ return:
// Checks if the symbol defines two-symbols Unicode sequence
bool doubleSymbol(const char c) {
static const char TWO_SYMBOLS_MASK = 0b110;
...
2
votes
2
answers
284
views
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<noAnimal*>(...);
BOOST_REQUIRE(animal);
BOOST_REQUIRE_EQUAL(animal->...
0
votes
1
answer
84
views
Exception when analyzing code
When analyzing some code using PVS-Studio 6.18.23098 I got the following stack trace in the PVS-Studio window:
Exception message: 0
Sequence contains no elements 0
Stack: at System.Linq....
1
vote
2
answers
145
views
PVS Studio complaining about dangerous macro expression
PVS Studio complains about a dangerous expression. The parameter 'msg' must be surrounded by parentheses on following code C++ code
#include <iostream>
#define X ("X")
#define Y ("Y")
#...
1
vote
1
answer
87
views
False positive warning PVS Studio: V808 object of type was created but was not utilized
PVS Studio 6.17 (Windows 7, 64Bit, VS2015) seems to give a wrong warning on the code below.
Warning "V808 'statuses' object of 'unordered_map' type was created but was not utilized".
Original code ...
1
vote
1
answer
285
views
How to properly integrate the pvs-studio into the kernel module makefile?
I'm going to check the simple open-source driver using pvc-studio and so far it does not work out. My system is Debian 4.6.0-amd64. I'm use native x86_64 gcc compiler.
Running with the commands
pvs-...
0
votes
1
answer
123
views
False positive warning PVS Studio: V821 Decreased perfomance. The 'rhs' variable can be constructed in a lower level scope
PVS Studio 6.17 (Windows 7, 64Bit, VS2017, C++-03) seems to give a wrong warning on following reduced code
#include <stack>
#include <string>
#include <vector>
bool fred(const std::...
2
votes
1
answer
89
views
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 ...
2
votes
1
answer
85
views
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 ...
0
votes
1
answer
118
views
False positive V595 The '_parent' pointer was utilized before it was verified against nullptr
I use PVS-Studio for my project Torrent File Editor. There is one false positive. Here no real problem but I get such error:
torrent-file-editor/abstracttreenode.h:138: error: V595 The '_parent' ...
4
votes
1
answer
344
views
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++ ...
1
vote
1
answer
254
views
Standalone PVS-Studio (free) still counts remaining clicks
I'm using PVS-Studio Standalone version 6.16.222236. I have added the special comments to all of my files with How-To-Use-PVS-Studio-FREE.exe so I presumed I can use it for free without any trial ...
25
votes
4
answers
4k
views
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 ...
5
votes
3
answers
473
views
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-...
0
votes
1
answer
42
views
RangeAnalysis and V3022
Consider the code below:
for (var i = int.MaxValue - 2; i < int.MaxValue; i++)
{
Console.WriteLine(i);
}
Console.WriteLine();
for (var i = int.MaxValue - 2; i <= int.MaxValue - 1; i++)
{
...
1
vote
1
answer
146
views
PVS-Studio complaining about float comparison
I scanned my code with PVS Studio analyzer and I am confused on why this error and how to fix this.
V550 An odd precise comparison: * dest == value. It's probably better to use a comparison with ...
0
votes
1
answer
44
views
Using DateTimeKind on DateTime triggers V3058
var dict1 = new Dictionary<DateTime, int>()
{
[new DateTime(0, DateTimeKind.Utc)] = 0,
[new DateTime(1, DateTimeKind.Utc)] = 1
}
dict1 triggers V3058 "V3058 An item with the same key '1'...
1
vote
2
answers
150
views
How to get rid of V677: custom declaration of a standard type warning
We are using a PVS Studio (free variant for opensource projects) in conjunction with travis-ci and it for some reason spawns errors for files located in /usr/local/clang-3.5.0/lib/clang/3.5.0/include:
...
1
vote
1
answer
271
views
Use wildcard to exclude paths in PVS-Studio configuration file
I would like to exclude 3rd-party libraries from analysis.
exclude-path=*/boost/*
exclude-path=*/llvm/*
But it doesn't work. I still have Boost-related messages in output log.
How to filter out ...
0
votes
1
answer
59
views
V3125 false positive when having empty statement after return
This minimal example triggers V3125 about member being used after it was verified against null. If I remove the extra semicolon after the first return statement V3125 is no longer triggered.
public ...
0
votes
1
answer
59
views
PVS-Studio: V641 - false positive for WIN API structs
The last member WCHAR Name[1] is assumed to be a string. It's a well-known technic.
// c:\Program Files (x86)\Windows Kits\8.0\Include\um\DbgHelp.h
typedef struct _SYMBOL_INFOW {
ULONG ...
0
votes
1
answer
40
views
PVS-Studio: warning V609 is generated even if denominator is checked
#define b1 0x01
#define b2 0x02
#define b3 0x04
#define b1 0x08
int flag = get_flag();
int x1 = ((flag & b1) ? 1 : 0) + ((flag & b2) ? 1 : 0);
int x2 = ((flag & b3) ? 1 : 0) + ((flag &...
0
votes
1
answer
45
views
PVS-Studio: warning V595 is generated even if COM methods results are checked
(1) If a result of IMoniker::BindToObject is S_OK then returned pointer is valid. But PVS-Studio marks it as V595. Why?
(2) If QueryInterface is succeeded then returned pointer is valid. But PVS-...
0
votes
1
answer
53
views
PVS-Studio: warning V595 is generated even if pointer is checked
In the following code there is already check for nullptr in (1):
int msg;
struct x * var[2];
if ((var[0] = get_x()) == nullptr) { // (1)
return;
}
if (var[0]->data != 11) { // (...
2
votes
1
answer
1k
views
PVS studio compare with sonarqube [closed]
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 ...
1
vote
1
answer
68
views
What is the easiest way to check just one *.c file from Linux kernel using pvs-studio?
What is the easiest way to check just one *.c file from Linux kernel using pvs-studio?
Kernel is a huge project, maybe there is a way to avoid compilation of all files.
0
votes
1
answer
57
views
PVS studio fails to find an incorrect usage of use after free
I was facing a bug in my little app that is using sqlpp11 to access the database. ASAN aborted the program with a use after free because I was using incorrectly the API. While trying to find out the ...
2
votes
1
answer
232
views
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'...