Skip to content

Commit

Permalink
Rank Calculation Out-of-Bounds Fix (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnHornhoover authored Dec 24, 2023
1 parent 21d2801 commit 44560a4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Racing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ static void racingEnd(CNSocket* sock, CNPacketData* data) {
std::vector<int>* rankRewards = &EPRewards[epInfo.EPID].second;

// top ranking
int maxRank = rankScores->size() - 1;
int topRank = 0;
while (rankScores->at(topRank) > topRankingPlayer.Score)
while (topRank < maxRank && rankScores->at(topRank) > topRankingPlayer.Score)
topRank++;

resp.iEPTopRank = topRank + 1;
Expand All @@ -144,7 +145,7 @@ static void racingEnd(CNSocket* sock, CNPacketData* data) {

// this ranking
int rank = 0;
while (rankScores->at(rank) > postRanking.Score)
while (rank < maxRank && rankScores->at(rank) > postRanking.Score)
rank++;

resp.iEPRank = rank + 1;
Expand Down

0 comments on commit 44560a4

Please sign in to comment.