Skip to content

Commit

Permalink
Fix #4951
Browse files Browse the repository at this point in the history
  • Loading branch information
Alayan-stk-2 committed Nov 29, 2023
1 parent a57ac41 commit 5bb5f5e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/replay/replay_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,37 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay, int ca
else
rd.m_minor_mode = "time-trial";


// sscanf always stops at whitespaces, but a track name may contain a whitespace
// Official tracks should avoid whitespaces in their name, but it
// unavoidably occurs with some addons or WIP tracks.
fgets(s, 1023, fd);
if (sscanf(s, "track: %1023s", s1) != 1)
if (std::strncmp(s, "track: ", 7) == 0)
{
int i = 0;
for(i = 7; s[i] != '\0'; i++)
{
// Break when newline is reached
if (s[i] == '\n' || s[i] == '\r')
break;
s1[i-7] = s[i];
}
s1[i-7] = '\0';

if (i >= 8)
{
rd.m_track_name = std::string(s1);
}
else
{
Log::warn("Replay", "Track name is empty in replay file, '%s'.", fn.c_str());
return false;
}
}
else
{
Log::warn("Replay", "Track info not found in replay file, '%s'.", fn.c_str());
return false;
}
rd.m_track_name = std::string(s1);

// If former official tracks are present as addons, show the matching replays.
if (rd.m_track_name.compare("greenvalley") == 0)
Expand Down

0 comments on commit 5bb5f5e

Please sign in to comment.