Was it worth the wait to find the bug? – InformTFB

Was it worth the wait to find the bug?

Was it worth the wait to find the bug?

You probably wondered whose code is better: an open source project or a closed one? after reading our blog, you might think that all the bugs were collected by open source projects. but this is not quite true. Errors are present in all projects, regardless of how they are stored. And the quality will be better where it is increased. this is a small note about how a bug was fixed in one project for 2 years, and could have been done in 5 minutes.

Timeline of events

Minetest is an open-source cross-platform game engine that contains about 200,000 lines of code in C, C++, and Lua. It allows you to create different game modes in voxel space. Supports multiplayer, and many mods from the community.

On November 10, 2018, Issue #7852 — item_image_button[]: button too small was discovered in the project bugtracker.

The description is as follows:

The button is too small resulting in the image exceeding its borders. Button should be the same size as inventory slots. See example below (using width and height of 1).

and a screenshot:

In the screenshot, you can notice a slight outflow of images beyond the border of the inner area of the buttons. The bug was noticed back in 2018, and the cause was found only now – in 2020.

the next event in this remarkable story was the publication of the technical article “pvs-studio: requests analysis pull in azure devops concept, and with the help of resident agents” in july 2020. Azure Azure DevOps, the same game was chosen-Minetest. The article contains several errors found, but we are interested in one specific one of them:

Rectangle in v636′.getHeight () expression / 16 ‘ type was an implicit cast of the type type ‘int’ to ‘float’. Consider Using an explicit type cast to avoid losing the fractional part. An example: Double a = (double) (x) / y;. hud.cpp 771

void drawItemStack(....) { float barheight = rect.getHeight() / 16; float barpad_x = rect.getWidth() / 16; float barpad_y = rect.getHeight() / 16; core::rect<s32> progressrect( rect.UpperLeftCorner.X + barpad_x, rect.LowerRightCorner.Y - barpad_y - barheight, rect.LowerRightCorner.X - barpad_x, rect.LowerRightCorner.Y - barpad_y); }

when dividing the width and height values by 16, the fractional part of the result is discarded, since the division is integer.

and so, six months later, the results of the analysis were noticed by the game developers, and issue 10726 — fix errors found by professional static code analyzer was created, where they established the connection of this bug with issue #7852. this rounding and distorted the size of the buttons.


Using static code analyzers allows you to save a lot of time on detecting errors in the code. It can be arbitrarily argued that the described bug is insignificant, but our experience shows that this is a typical life cycle of an error of any criticality.

Suppose there was a serious bug here. they would have spent all their energy on fixing it, and in an hour of debugging they would have found and fixed it. But the analyzer would still find it in a couple of minutes.

Thus, we can conclude that automatic error detection methods bring undeniable benefits to the project being developed. tools like pvs-studio should be considered as an addition to codereview with other programmers, not a replacement for this process.

Valery Radokhleb
Valery Radokhleb
Web developer, designer

Leave a Reply

Your email address will not be published. Required fields are marked *