BUG OF THE MONTH | An odd implicit type casting
V601 The integer type is implicitly cast to the char type. Game.cpp 4997
void Game::loadquick(....) { .... else if (pKey == "totalflips") { totalflips = atoi(pText); } else if (pKey == "hardestroom") { hardestroom = atoi(pText); } else if (pKey == "hardestroomdeaths") { hardestroomdeaths = atoi(pText); } .... }
To understand what’s going on, let’s take a look at the variables’ definitions from the given part of code:
//Some stats: int totalflips; std::string hardestroom; int hardestroomdeaths;
totalflips and hardestroomdeaths variables are integer, so it’s perfectly normal to assign them the result of the atoi function. But what happens if you assign an integer value to std::string? Such assignment turns out to be valid from the language perspective. As a result, an unclear value will be written in the hardestroom variable!
Please click here to see more bugs from this project.