summaryrefslogtreecommitdiffstats
path: root/adventure
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-03-21 17:14:15 +0000
committerchristos <christos@NetBSD.org>2006-03-21 17:14:15 +0000
commitc75621391dae5a9b1412c1964ee8f6debf2c1035 (patch)
treef84fdd8678f16bb527e6018b8401e3d3fe6849a3 /adventure
parentea7a50190d992fca1a93ad925f543277e2e66cab (diff)
downloadbsdgames-darwin-c75621391dae5a9b1412c1964ee8f6debf2c1035.tar.gz
bsdgames-darwin-c75621391dae5a9b1412c1964ee8f6debf2c1035.tar.zst
bsdgames-darwin-c75621391dae5a9b1412c1964ee8f6debf2c1035.zip
Coverity CID 2737: Handle linked-lists properly. Use calloc instead of malloc
so that we don't end up storing garbage accidentally and the next pointer is initialized. If there is an inconsistency in the file abort instead of dereferencing NULL.
Diffstat (limited to 'adventure')
-rw-r--r--adventure/io.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/adventure/io.c b/adventure/io.c
index 44a88b52..4ef081ef 100644
--- a/adventure/io.c
+++ b/adventure/io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.18 2006/03/18 23:33:38 christos Exp $ */
+/* $NetBSD: io.c,v 1.19 2006/03/21 17:14:15 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.18 2006/03/18 23:33:38 christos Exp $");
+__RCSID("$NetBSD: io.c,v 1.19 2006/03/21 17:14:15 christos Exp $");
#endif
#endif /* not lint */
@@ -361,9 +361,8 @@ rtrav(void)
if (locc == -1)
return;
if (locc != oldloc) { /* getting a new entry */
- t = travel[locc] = (struct travlist *)
- malloc(sizeof(struct travlist));
- if ( t == NULL)
+ t = travel[locc] = calloc(1, sizeof(*t));
+ if (t == NULL)
err(1, NULL);
/* printf("New travel list for %d\n",locc); */
entries = 0;
@@ -384,8 +383,10 @@ rtrav(void)
m = atoi(buf);
}
while (breakch != LF) { /* only do one line at a time */
- if (t && entries++) {
- t->next = malloc(sizeof(struct travlist));
+ if (t == NULL)
+ abort();
+ if (entries++) {
+ t->next = calloc(1, sizeof(*t));
if (t->next == NULL)
err(1, NULL);
t = t->next;