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

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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.

>
>
>
WTF?

WTF?

Oct 01 2013
Author:

I'm currently experiencing a strong cognitive dissonance, and it won't let me go. You see, I visit various programmers' forums and see topics where people discuss noble ideas about how to write super-reliable classes; somebody tells he has his project built with the switches -Wall -Wextra -pedantic -Weffc++, and so on. But, God, where are all these scientific and technological achievements? Why do I come across most silly mistakes again and again? Perhaps something is wrong with me?

0215_WTF/image1.png

Well, there are actually wonderful projects too. Such is, for instance, the library ALGLIB. Source code of this library is very interesting. Developers write code in Pascal and then code translating into C++ and C# automatically. Besides a number of other advantages, this approach allows them to catch quite many diverse bugs, since one and the same program is built by compilers supporting different languages. But this is quite another story, and perhaps we will tell it someday in a joint article by the library's author and me.

Such wonderful exceptions to the common state of things only enhance my cognitive dissonance. Now try to imagine what I feel. Say, I take a complex package of computer simulation software and see not a single bug there. I'm glad about the high-quality code and just a bit sad because the package's author will never buy PVS-Studio. Well, never mind. Then I take the project OpenCOLLADA and check it. WTF? I have no other words to express my feelings. What do you think about constructors like the ones below?

struct short2
{
  short values[2];
  short2(short s1, short s2)
  {
    values[0] = s1;
    values[2] = s2;
  }
  ....
};

struct double2
{
  double values[2];
  double2( double d1, double d2)
  {
    values[0]=d1;
    values[0]=d2;
  }
  ....
}

The programmer missed the array in the first constructor and forgot to change the index in the copied-and-pasted line in the second constructor.

I'm sorry for posting this picture, guys, but it shows quite exactly what I feel.

0215_WTF/image2.png

Other constructors are also a source of much wonder and fun. For example, these ones are very nice:

struct ParserString : public UnionString
{
  ParserString()
  {
    UnionString::str = 0;
    UnionString::length = 0;
  }

  ParserString(const int& val)
  {
    ParserString();
  }
};

Instead of calling another constructor, a temporary object is created and gets destroyed at once, whereas the class members are left uninitialized. More about it.

Oh my God, where are all those people who with so much zeal write about C++11, lambdas, Boost.Asio, shared_ptr, constexpr, LINQ? How could the following code have been written:

struct ObjectGroups{
  componentList objectGrpCompList;
  int objectGroupId;
  short objectGrpColor;
  void write(FILE* file) const;
}* objectGroups;

void write(FILE* file) const
{
  size_t size = sizeof(objectGroups)/sizeof(ObjectGroups);
  for(size_t i=0; i<size; ++i)
  {
    objectGroups[i].write(file);
    if(i+1<size) fprintf(file," ");
  }
}

The programmer just divided the pointer size by the structure's size and got 0. What the hell did he mean to do? WTF?

Well, even when you can guess what and how the programmer wanted to write into a file, you feel no better.

void write(FILE* file) const
{
  fprintf(file,"%i %i %i %i ",
    sDivisionCount, tDivisionCount, uDivisionCount, pointCount);
  size_t size = pointCount*3;
  for(size_t i; i<size; ++i)
  {
    fprintf(file, "%f", points[i]);
    if(i+1<size) fprintf(file, " ");
  }
}

If you don't see the bug, I'll prompt. The variable 'i' is not initialized: for(size_t i; i<size; ++i).

Sorry for sharing all this with you - it just makes me feel better somehow. And I also use this opportunity to remind you that all these bugs were found by the PVS-Studio static code analyzer. The locations of the above mentioned and some other notable bugs are listed in this text file. As usual, if somebody wants to check this project more thoroughly, ask me for a key.

Good luck and may your code stay bugless!

Popular related articles
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…
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…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
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…
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…
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…
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…
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…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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