To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
How we sympathize with a question on St…

How we sympathize with a question on StackOverflow but keep silent

Oct 25 2021
Author:

On the stackoverflow.com website, we frequently see questions about how to look for bugs of a certain type. We know that PVS-Studio can solve the problem. Unfortunately, we have to keep silent. Otherwise, StackOverflow moderators may consider it as an obvious attempt to promote our product. This article describes a particular case of such a situation that makes us suffer deeply.

0877_Stackoverflow_And_Suffering/image1.png

The following question: "Scan-Build for clang-13 not showing errors" asked by kratos from India, made me write this article. This person asks how to look for patterns of the following type:

  • writing integer values other than 0 and 1 to a bool type variable;
  • virtual functions call in the constructor and destructor.

Here's the code cited as an example:

int f1(){
int a=5;
short b=4;
bool a1=a;//maybe warn
bool b1=b;//maybe warn
if(a1&&b1)return 1;
return 0;
}
class M{
public:
    virtual int GetAge(){return 0;}
};
class P:public M{
public:
    virtual int GetAge(){return 1;}
    P(){GetAge();}//maybe warn
    ~P(){GetAge();}//maybe warn
};

int main(){
    return 0;
}

To search for errors, kratos tried to use the Clang 13 compiler, but this isn't working.

I don't know whether you can find such errors with Clang or not – didn't study this issue. Most likely, to find errors, you just have to specify the right flag for the compiler.

However, I am tempted to reply something as: try PVS-Studio. Although no – this is not enough to post an answer, but I was eager to add the comment as:

I can't tell you whether you can search for these errors with Clang, but the PVS-Studio static analyzer finds these errors right away: an example on the Compiler Explorer website. Try it, maybe it's gonna work :)

The first suspicious pattern triggers the analyzer in two ways at once. Therefore, we have 4 warnings in total:

  • 6:1: note: V547 The 'A = a' expression is equivalent to the 'A = true' expression.
  • 6:1: warning: V786 It is odd that value 'a' is assigned to the 'a1' variable. The value range of 'a1' variable: [0, 1].
  • 7:1: note: V547 The 'A = b' expression is equivalent to the 'A = true' expression.
  • 7:1: warning: V786 It is odd that value 'b' is assigned to the 'b1' variable. The value range of 'b1' variable: [0, 1].

And another two messages relating to the virtual functions call:

  • 18:1: error: V1053 Calling the 'GetAge' virtual function in the constructor may lead to unexpected result at runtime.
  • 19:1: error: V1053 Calling the 'GetAge' virtual function in the destructor may lead to unexpected result at runtime.

Some programmers may find this information useful. Unfortunately, no one will know about this on StackOverflow :(.

First, the answer contains a commercial tool. Moreover, it's the first question from kratos.

0877_Stackoverflow_And_Suffering/image2.png

It may look as if I created a virtual user on purpose, asked a question, and answered it to promote PVS-Studio in a favorable light.

So, I can't really post an answer. StackOverflow moderators may think that it's a stupid spam trick and ban me :). Maybe we asked a question and answered it... At least we should have leveled up our virtual user asking the question... Not creative at all :).

Well, I didn't reply to the question on StackOverflow, but I wrote this little note. Eventually, I feel relieved, and readers enjoy an unusual story from the life of the PVS-Studio team :).

Note. You may tartly say that such a comment promotes a proprietary tool. And StackOverflow must fine/ban us for this. I don't think so. For many developers, it won't make any difference which tool to use. You can use PVS-Studio for free in various scenarios: "Ways to Get a Free PVS-Studio License".

Thanks for your attention. By the way, since we were talking about Clang, I invite you to take a look at a recent note "Detecting errors in the LLVM release 13.0.0". Wish you bugless code!

Popular related articles
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept