summaryrefslogtreecommitdiffstats
path: root/monop
diff options
context:
space:
mode:
authorjsm <jsm@NetBSD.org>1999-09-09 17:27:58 +0000
committerjsm <jsm@NetBSD.org>1999-09-09 17:27:58 +0000
commit05028c2aa439ddb8c5624303ab13b755c79e3930 (patch)
tree4dbfd0bd9517b044c230067c63c13f98608d7599 /monop
parent73294a12acd4e9ce3be5c49adc331ab62d3a398f (diff)
downloadbsdgames-darwin-05028c2aa439ddb8c5624303ab13b755c79e3930.tar.gz
bsdgames-darwin-05028c2aa439ddb8c5624303ab13b755c79e3930.tar.zst
bsdgames-darwin-05028c2aa439ddb8c5624303ab13b755c79e3930.zip
Check for failure of malloc() and calloc() at various places in the games.
Diffstat (limited to 'monop')
-rw-r--r--monop/cards.c6
-rw-r--r--monop/initdeck.c7
-rw-r--r--monop/monop.c11
-rw-r--r--monop/monop.h3
-rw-r--r--monop/prop.c6
5 files changed, 23 insertions, 10 deletions
diff --git a/monop/cards.c b/monop/cards.c
index 079cc236..1b330db7 100644
--- a/monop/cards.c
+++ b/monop/cards.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cards.c,v 1.9 1999/09/08 21:57:18 jsm Exp $ */
+/* $NetBSD: cards.c,v 1.10 1999/09/09 17:27:58 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: cards.c,v 1.9 1999/09/08 21:57:18 jsm Exp $");
+__RCSID("$NetBSD: cards.c,v 1.10 1999/09/09 17:27:58 jsm Exp $");
#endif
#endif /* not lint */
@@ -102,6 +102,8 @@ set_up(dp)
int i;
dp->offsets = (off_t *) calloc(sizeof (off_t), dp->num_cards);
+ if (dp->offsets == NULL)
+ errx(1, "out of memory");
if (fread(dp->offsets, sizeof(off_t), dp->num_cards, deckf) !=
dp->num_cards) {
perror(cardfile);
diff --git a/monop/initdeck.c b/monop/initdeck.c
index e2cda3b7..a4b76b3e 100644
--- a/monop/initdeck.c
+++ b/monop/initdeck.c
@@ -1,4 +1,4 @@
-/* $NetBSD: initdeck.c,v 1.9 1999/09/08 21:57:18 jsm Exp $ */
+/* $NetBSD: initdeck.c,v 1.10 1999/09/09 17:27:59 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,10 +43,11 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)initdeck.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: initdeck.c,v 1.9 1999/09/08 21:57:18 jsm Exp $");
+__RCSID("$NetBSD: initdeck.c,v 1.10 1999/09/09 17:27:59 jsm Exp $");
#endif
#endif /* not lint */
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -101,6 +102,8 @@ main(ac, av)
*/
CC_D.offsets = (off_t *)calloc(CC_D.num_cards + 1, sizeof (off_t));
CH_D.offsets = (off_t *)calloc(CH_D.num_cards + 1, sizeof (off_t));
+ if (CC_D.offsets == NULL || CH_D.offsets == NULL)
+ errx(1, "out of memory");
fseek(inf, 0L, SEEK_SET);
if ((outf = fopen(outfile, "w")) == NULL) {
perror(outfile);
diff --git a/monop/monop.c b/monop/monop.c
index 001331cb..5b071759 100644
--- a/monop/monop.c
+++ b/monop/monop.c
@@ -1,4 +1,4 @@
-/* $NetBSD: monop.c,v 1.7 1999/09/08 21:45:28 jsm Exp $ */
+/* $NetBSD: monop.c,v 1.8 1999/09/09 17:27:59 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: monop.c,v 1.7 1999/09/08 21:45:28 jsm Exp $");
+__RCSID("$NetBSD: monop.c,v 1.8 1999/09/09 17:27:59 jsm Exp $");
#endif
#endif /* not lint */
@@ -116,6 +116,8 @@ blew_it:
break;
}
cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
+ if (play == NULL)
+ errx(1, "out of memory");
for (i = 0; i < num_play; i++) {
over:
printf("Player %d's name: ", i + 1);
@@ -124,7 +126,10 @@ over:
if (sp == buf)
goto over;
*sp++ = '\0';
- strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
+ name_list[i] = play[i].name = (char *)calloc(1, sp - buf);
+ if (name_list[i] == NULL)
+ errx(1, "out of memory");
+ strcpy(play[i].name, buf);
play[i].money = 1500;
}
name_list[i++] = "done";
diff --git a/monop/monop.h b/monop/monop.h
index 98db7e02..3e0cf7ab 100644
--- a/monop/monop.h
+++ b/monop/monop.h
@@ -1,4 +1,4 @@
-/* $NetBSD: monop.h,v 1.8 1999/09/08 21:17:52 jsm Exp $ */
+/* $NetBSD: monop.h,v 1.9 1999/09/09 17:27:59 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -35,6 +35,7 @@
* @(#)monop.h 8.1 (Berkeley) 5/31/93
*/
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/monop/prop.c b/monop/prop.c
index aec1f76a..5c4d27e1 100644
--- a/monop/prop.c
+++ b/monop/prop.c
@@ -1,4 +1,4 @@
-/* $NetBSD: prop.c,v 1.5 1999/08/21 10:40:04 simonb Exp $ */
+/* $NetBSD: prop.c,v 1.6 1999/09/09 17:27:59 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: prop.c,v 1.5 1999/08/21 10:40:04 simonb Exp $");
+__RCSID("$NetBSD: prop.c,v 1.6 1999/09/09 17:27:59 jsm Exp $");
#endif
#endif /* not lint */
@@ -75,6 +75,8 @@ add_list(plr, head, op_sqr)
OWN *op;
op = (OWN *)calloc(1, sizeof (OWN));
+ if (op == NULL)
+ errx(1, "out of memory");
op->sqr = &board[op_sqr];
val = value(op->sqr);
last_tp = NULL;