Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] (PR#13207) sanity check in get_player
Home

[Freeciv-Dev] (PR#13207) sanity check in get_player

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13207) sanity check in get_player
From: "Jason Dorje Short" <jdorje@xxxxxxxxx>
Date: Fri, 3 Jun 2005 10:09:27 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13207 >

This patch adds a sanity check in get_player.  If the player ID is out
of range we return NULL instead of a garbage pointer.

-jason

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.216
diff -u -r1.216 game.c
--- common/game.c       21 May 2005 19:40:24 -0000      1.216
+++ common/game.c       3 Jun 2005 17:08:39 -0000
@@ -492,7 +492,11 @@
 **************************************************************************/
 struct player *get_player(int player_id)
 {
-    return &game.players[player_id];
+  if (player_id < 0 || player_id >= ARRAY_SIZE(game.players)) {
+    assert(0);
+    return NULL;
+  }
+  return &game.players[player_id];
 }
 
 bool is_valid_player_id(int player_id)

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13207) sanity check in get_player, Jason Dorje Short <=