From 045be7d2c5e08408453d6c969dc863e75f9cbfbb Mon Sep 17 00:00:00 2001 From: dholland Date: Sat, 23 Feb 2008 22:28:46 +0000 Subject: Fixes from OpenBSD. - If a player goes bankrupt buying a property (which shouldn't be allowed, but I guess it is), don't cause them to resign to themselves. - Use "NULL", not "0", for pointers. - Avoid undefined behavior adjusting the current player after resigning. - Don't leak the memory used to store player names. The last of these is disabled for the moment because we have the pointers in question tagged const. Will see to this when I'm finished merging. --- monop/trade.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'monop') diff --git a/monop/trade.c b/monop/trade.c index 1d210a43..4e130af3 100644 --- a/monop/trade.c +++ b/monop/trade.c @@ -1,4 +1,4 @@ -/* $NetBSD: trade.c,v 1.12 2008/02/19 10:48:47 dholland Exp $ */ +/* $NetBSD: trade.c,v 1.13 2008/02/23 22:28:46 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: trade.c,v 1.12 2008/02/19 10:48:47 dholland Exp $"); +__RCSID("$NetBSD: trade.c,v 1.13 2008/02/23 22:28:46 dholland Exp $"); #endif #endif /* not lint */ @@ -252,6 +252,9 @@ resign() case RR: case PRPTY: new_own = board[cur_p->loc].owner; + /* If you ran out of money by buying current location */ + if (new_own == player) + new_own = num_play; break; default: /* Chance, taxes, etc */ new_own = num_play; @@ -307,16 +310,19 @@ resign() if (cur_p->num_gojf) ret_card(cur_p); } +#if 0 /* notyet */ + free(name_list[player]); +#endif for (i = player; i < num_play; i++) { name_list[i] = name_list[i+1]; if (i + 1 < num_play) play[i] = play[i+1]; } - name_list[num_play--] = 0; + name_list[num_play--] = NULL; for (i = 0; i < N_SQRS; i++) if (board[i].owner > player) --board[i].owner; - player = --player < 0 ? num_play - 1 : player; + player = player == 0 ? num_play - 1 : player - 1; next_play(); if (num_play < 2) { printf("\nThen %s WINS!!!!!\n", play[0].name); -- cgit v1.2.3-56-ge451