summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>1998-09-12 01:54:43 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>1998-09-12 01:54:43 +0000
commit409a4693a193ffb767eb4291a7b8029d100f40eb (patch)
treed7a8f2f81695cdbcf85ef6ff064549d36743f7cf
parent905786119ba5116c9568dbb26deeac7f94956327 (diff)
check for malloc() failure; jsm28@cam.ac.uk
-rw-r--r--games/adventure/io.c14
-rw-r--r--games/adventure/vocab.c8
2 files changed, 15 insertions, 7 deletions
diff --git a/games/adventure/io.c b/games/adventure/io.c
index 2ff929b41ae..4b936a73dd2 100644
--- a/games/adventure/io.c
+++ b/games/adventure/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.5 1998/08/31 02:29:41 pjanzen Exp $ */
+/* $OpenBSD: io.c,v 1.6 1998/09/12 01:54:42 pjanzen Exp $ */
/* $NetBSD: io.c,v 1.3 1995/04/24 12:21:37 cgd Exp $ */
/*-
@@ -43,12 +43,13 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: io.c,v 1.5 1998/08/31 02:29:41 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: io.c,v 1.6 1998/09/12 01:54:42 pjanzen 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>
@@ -392,6 +393,8 @@ rtrav() /* read travel table */
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;
@@ -411,8 +414,11 @@ rtrav() /* read travel table */
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 */
@@ -587,7 +593,7 @@ pspeak(m, skip) /* read, decrypt an print a ptext message */
msg = &ptext[m];
if ((tbuf = (char *) malloc(msg->txtlen + 1)) == 0)
- bug(108);
+ errx(1, "Out of memory!");
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
s = tbuf;
diff --git a/games/adventure/vocab.c b/games/adventure/vocab.c
index 6514104d2b3..c5c6fd849f3 100644
--- a/games/adventure/vocab.c
+++ b/games/adventure/vocab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vocab.c,v 1.5 1998/08/31 02:29:46 pjanzen Exp $ */
+/* $OpenBSD: vocab.c,v 1.6 1998/09/12 01:54:42 pjanzen Exp $ */
/* $NetBSD: vocab.c,v 1.2 1995/03/21 12:05:13 cgd Exp $ */
/*-
@@ -43,12 +43,13 @@
#if 0
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: vocab.c,v 1.5 1998/08/31 02:29:46 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: vocab.c,v 1.6 1998/09/12 01:54:42 pjanzen 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"
@@ -165,7 +166,8 @@ vocab(word, type, value) /* look up or store a word */
if (h->val) /* already got an entry? */
goto exitloop2;
h->val = value;
- h->atab = malloc(length(word));
+ if ((h->atab = malloc(length(word))) == NULL)
+ errx(1, "Out of memory!");
for (s = word, t = h->atab; *s;)
*t++ = *s++ ^ '=';
*t = 0 ^ '=';