fixed out-of-bounds bug when score was not added to high score list
authorHolger Schemel <info@artsoft.org>
Sat, 30 Oct 2021 12:16:43 +0000 (14:16 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Oct 2021 12:16:43 +0000 (14:16 +0200)
If the score is not added to the local high score list for a solved
level (because the high score table is completely full, and the new
score is not better than the lowest score entry in the list), there
was an out-of-bounds bug caused (by accessing the score array at
position "-1", which was not correctly handled as "no score entry").

This uncaught error condition could have caused various misbehavior
(inclusing crashes) of the game. This change fixes this bug.

src/game.c

index abc56d238a167278eb7769778ba0edc4e5269c40..4d1d9a858244e4283d7bbbdf7f085ec5c4fc3b95 100644 (file)
@@ -5140,12 +5140,12 @@ void NewHighScore(int level_nr, boolean tape_saved)
 
     // store last added local score entry (before merging server scores)
     scores.last_added_local = scores.last_added;
 
     // store last added local score entry (before merging server scores)
     scores.last_added_local = scores.last_added;
-  }
 
 
-  if (game.LevelSolved_SaveTape)
-  {
-    SaveScoreTape(level_nr);
-    SaveServerScore(level_nr, tape_saved);
+    if (game.LevelSolved_SaveTape)
+    {
+      SaveScoreTape(level_nr);
+      SaveServerScore(level_nr, tape_saved);
+    }
   }
 }
 
   }
 }