📜 ⬆️ ⬇️

WTF?

PVS-Studio, WTF?
I do not leave cognitive dissonance. The forums discuss sublime ideas about writing super-reliable classes, someone says that his project is going with the keys -Wall -Wextra -pedantic -Weffc ++. Lord, where are all these achievements of science and technology? Why do I see stupid mistakes around? Maybe something is wrong with me?



No, in fact, I see great projects. An example is the ALGLIB library. This is a very interesting library in terms of code. It is written in Pascal, and then translated into C ++, C #. Among other various advantages, this approach allows you to catch a lot of different errors, since the same program is compiled by compilers for different languages. However, this is a separate story. Perhaps we will somehow write a joint note with the author of this library.
')
Such pleasant exceptions, perhaps, further exacerbate the dissonance. Just imagine my feelings. I take a complex package of numerical analysis and find no errors in it. I am happy for the quality code. It’s a little sad that PVS-Studio cannot be sold to such a person. Anyway. I take the project OpenCOLLADA . I check. WTF? Other words I can not find. How do you like these designers?
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 first constructor missed the array. In the second we copied the line and forgot to change the index.

Forgive the reader, I can not refrain from the picture. She very accurately conveys my emotions.

WTF

"Deliver" and other designers. For example, this is cute:
 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 immediately destroyed. And class members remain uninitialized. More details .

Lord, where are the people who, having rolled up their sleeves, write articles about C ++ 11, lambdas, Boost.Asio, shared_ptr, constexpr, LINQ. Why I see in the code:
 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," "); } } 

They divided the size of the pointer into the size of the structure and got 0. What did they want to do here? WTF?

However, when it is even clear what and how they wanted to write to the file, this is no easier.
 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 have not noticed a bug, I will tell you. The variable 'i' is not initialized: for (size_t i; i <size; ++ i).

Sorry to share it all with you. It's easier for me. At the same time, I naturally say that these errors were found with the help of the PVS-Studio static code analyzer. I posted the location of these and some other funny errors in this text file . And as always, if there are those who wish to check this project more carefully, I am ready to share a key.

Good luck and you hopeless code!

Source: https://habr.com/ru/post/195928/


All Articles