summaryrefslogtreecommitdiffstats
path: root/adventure
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>1998-09-13 15:24:09 +0000
committerhubertf <hubertf@NetBSD.org>1998-09-13 15:24:09 +0000
commit1d750a7b418d5ff128a97e0d270bae3681f64b96 (patch)
treeb1c07299f99c4249b8dd68008a2fd0367bbb7346 /adventure
parent5ad3edeee918edc8b92266e5b533f421b704c47e (diff)
downloadbsdgames-darwin-1d750a7b418d5ff128a97e0d270bae3681f64b96.tar.gz
bsdgames-darwin-1d750a7b418d5ff128a97e0d270bae3681f64b96.tar.zst
bsdgames-darwin-1d750a7b418d5ff128a97e0d270bae3681f64b96.zip
check for malloc failures (PR#6136 by Joseph Myers <jsm28@cam.ac.uk>)
Diffstat (limited to 'adventure')
-rw-r--r--adventure/io.c16
-rw-r--r--adventure/vocab.c7
2 files changed, 16 insertions, 7 deletions
diff --git a/adventure/io.c b/adventure/io.c
index 3158991d..548339bf 100644
--- a/adventure/io.c
+++ b/adventure/io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.8 1998/09/13 00:07:24 hubertf Exp $ */
+/* $NetBSD: io.c,v 1.9 1998/09/13 15:24:09 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -43,12 +43,13 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: io.c,v 1.8 1998/09/13 00:07:24 hubertf Exp $");
+__RCSID("$NetBSD: io.c,v 1.9 1998/09/13 15:24:09 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: file i/o and user i/o */
+#include <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -355,6 +356,8 @@ rtrav()
return;
if (locc != oldloc) { /* getting a new entry */
t = travel[locc] = (struct travlist *) malloc(sizeof(struct travlist));
+ if ( t == NULL)
+ errx(1, "Out of memory!");
/* printf("New travel list for %d\n",locc); */
entries = 0;
oldloc = locc;
@@ -374,8 +377,11 @@ rtrav()
m = atoi(buf);
}
while (breakch != LF) { /* only do one line at a time */
- if (entries++)
+ if (entries++) {
t = t->next = (struct travlist *) malloc(sizeof(struct travlist));
+ if (t == NULL)
+ errx(1, "Out of memory!");
+ }
t->tverb = rnum(); /* get verb from the file */
t->tloc = n; /* table entry mod 1000 */
t->conditions = m; /* table entry / 1000 */
@@ -548,8 +554,8 @@ pspeak(m, skip) /* read, decrypt an print a ptext message */
char *tbuf;
msg = &ptext[m];
- if ((tbuf = (char *) malloc(msg->txtlen + 1)) == 0)
- bug(108);
+ if ((tbuf = (char *) malloc(msg->txtlen + 1)) == NULL)
+ errx(1, "Out of memory!");
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
s = tbuf;
diff --git a/adventure/vocab.c b/adventure/vocab.c
index d97be635..2685f8a8 100644
--- a/adventure/vocab.c
+++ b/adventure/vocab.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vocab.c,v 1.7 1998/09/13 00:07:24 hubertf Exp $ */
+/* $NetBSD: vocab.c,v 1.8 1998/09/13 15:24:09 hubertf Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -43,12 +43,13 @@
#if 0
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: vocab.c,v 1.7 1998/09/13 00:07:24 hubertf Exp $");
+__RCSID("$NetBSD: vocab.c,v 1.8 1998/09/13 15:24:09 hubertf Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: data structure routines */
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "hdr.h"
@@ -163,6 +164,8 @@ vocab(word, type, value) /* look up or store a word */
goto exitloop2;
h->val = value;
h->atab = malloc(length(word));
+ if (h->atab == NULL)
+ errx(1, "Out of memory!");
for (s = word, t = h->atab; *s;)
*t++ = *s++ ^ '=';
*t = 0 ^ '=';