PolyMarsDev / Cursor-Custodian

A small SDL2 game made in 48 hours
116 stars 34 forks source link

Pointer to dealocated memory #16

Open wimos-ai opened 2 years ago

wimos-ai commented 2 years ago

In player.cpp, Player::getScore and Player::getHighScore return pointers to dealocated memory.

const char* Player::getHighscore() { std::string s = std::to_string(highscore); s = "BEST: " + s; return s.c_str(); }

const char* Player::getScore() { std::string s = std::to_string(score); s = "DISTANCE: " + s; return s.c_str(); }

When std::string s goes out of scope, the const char* that s.c_str returns is invalidated. Access to the underlying string may be garbage, cause a segfault, or cause other nasty issues.

wimos-ai commented 2 years ago

Fixed in pull request #17