summaryrefslogtreecommitdiffstats
path: root/monop
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2008-02-23 22:28:46 +0000
committerdholland <dholland@NetBSD.org>2008-02-23 22:28:46 +0000
commit045be7d2c5e08408453d6c969dc863e75f9cbfbb (patch)
tree2a7bb40776b0151707d62df71da79af1fce242a7 /monop
parent59b92506bcb68b77b0568fd6c0aa6c0dc14ab490 (diff)
downloadbsdgames-darwin-045be7d2c5e08408453d6c969dc863e75f9cbfbb.tar.gz
bsdgames-darwin-045be7d2c5e08408453d6c969dc863e75f9cbfbb.tar.zst
bsdgames-darwin-045be7d2c5e08408453d6c969dc863e75f9cbfbb.zip
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.
Diffstat (limited to 'monop')
-rw-r--r--monop/trade.c14
1 files changed, 10 insertions, 4 deletions
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);