Skip to content

Pointer to dealocated memory #16

@wimos-ai

Description

@wimos-ai

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions