summaryrefslogtreecommitdiffstats
path: root/adventure
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-03-18 23:31:19 +0000
committerchristos <christos@NetBSD.org>2006-03-18 23:31:19 +0000
commitb22c03d38161d83cf068000f0f356ce84909d101 (patch)
treeea67598403ff892f4c4c8dfb1e1830776bd26e23 /adventure
parent00a63a8f8922196723c2c50f273e8406378b26dd (diff)
downloadbsdgames-darwin-b22c03d38161d83cf068000f0f356ce84909d101.tar.gz
bsdgames-darwin-b22c03d38161d83cf068000f0f356ce84909d101.tar.zst
bsdgames-darwin-b22c03d38161d83cf068000f0f356ce84909d101.zip
Coverity CID 777: Fix NULL pointer deref and de-obfuscate code.
Diffstat (limited to 'adventure')
-rw-r--r--adventure/io.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/adventure/io.c b/adventure/io.c
index aed2deb4..6ad8b0e5 100644
--- a/adventure/io.c
+++ b/adventure/io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.16 2005/07/01 00:03:36 jmc Exp $ */
+/* $NetBSD: io.c,v 1.17 2006/03/18 23:31:19 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: io.c,v 1.16 2005/07/01 00:03:36 jmc Exp $");
+__RCSID("$NetBSD: io.c,v 1.17 2006/03/18 23:31:19 christos Exp $");
#endif
#endif /* not lint */
@@ -353,7 +353,7 @@ rtrav(void)
for (oldloc = -1;;) { /* get another line */
/* end of entry */
- if ((locc = rnum()) != oldloc && oldloc >= 0) {
+ if ((locc = rnum()) != oldloc && oldloc >= 0 && t) {
t->next = 0; /* terminate the old entry */
/* printf("%d:%d entries\n",oldloc,entries); */
/* twrite(oldloc); */
@@ -384,11 +384,11 @@ rtrav(void)
m = atoi(buf);
}
while (breakch != LF) { /* only do one line at a time */
- if (entries++) {
- t = t->next = (struct travlist *)
- malloc(sizeof(struct travlist));
- if (t == NULL)
+ if (t && entries++) {
+ t->next = malloc(sizeof(struct travlist));
+ if (t->next == NULL)
err(1, NULL);
+ t = t->next;
}
t->tverb = rnum(); /* get verb from the file */
t->tloc = n; /* table entry mod 1000 */