check for malloc failures (PR#6136 by Joseph Myers <jsm28@cam.ac.uk>)
This commit is contained in:
parent
9e7f2724b9
commit
878ef9cb13
@ -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
|
* Copyright (c) 1991, 1993
|
||||||
@ -43,12 +43,13 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
|
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/* Re-coding of advent in C: file i/o and user i/o */
|
/* Re-coding of advent in C: file i/o and user i/o */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -355,6 +356,8 @@ rtrav()
|
|||||||
return;
|
return;
|
||||||
if (locc != oldloc) { /* getting a new entry */
|
if (locc != oldloc) { /* getting a new entry */
|
||||||
t = travel[locc] = (struct travlist *) malloc(sizeof(struct travlist));
|
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); */
|
/* printf("New travel list for %d\n",locc); */
|
||||||
entries = 0;
|
entries = 0;
|
||||||
oldloc = locc;
|
oldloc = locc;
|
||||||
@ -374,8 +377,11 @@ rtrav()
|
|||||||
m = atoi(buf);
|
m = atoi(buf);
|
||||||
}
|
}
|
||||||
while (breakch != LF) { /* only do one line at a time */
|
while (breakch != LF) { /* only do one line at a time */
|
||||||
if (entries++)
|
if (entries++) {
|
||||||
t = t->next = (struct travlist *) malloc(sizeof(struct travlist));
|
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->tverb = rnum(); /* get verb from the file */
|
||||||
t->tloc = n; /* table entry mod 1000 */
|
t->tloc = n; /* table entry mod 1000 */
|
||||||
t->conditions = m; /* table entry / 1000 */
|
t->conditions = m; /* table entry / 1000 */
|
||||||
@ -548,8 +554,8 @@ pspeak(m, skip) /* read, decrypt an print a ptext message */
|
|||||||
char *tbuf;
|
char *tbuf;
|
||||||
|
|
||||||
msg = &ptext[m];
|
msg = &ptext[m];
|
||||||
if ((tbuf = (char *) malloc(msg->txtlen + 1)) == 0)
|
if ((tbuf = (char *) malloc(msg->txtlen + 1)) == NULL)
|
||||||
bug(108);
|
errx(1, "Out of memory!");
|
||||||
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
|
memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */
|
||||||
s = tbuf;
|
s = tbuf;
|
||||||
|
|
||||||
|
@ -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
|
* Copyright (c) 1991, 1993
|
||||||
@ -43,12 +43,13 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
|
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/* Re-coding of advent in C: data structure routines */
|
/* Re-coding of advent in C: data structure routines */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "hdr.h"
|
#include "hdr.h"
|
||||||
@ -163,6 +164,8 @@ vocab(word, type, value) /* look up or store a word */
|
|||||||
goto exitloop2;
|
goto exitloop2;
|
||||||
h->val = value;
|
h->val = value;
|
||||||
h->atab = malloc(length(word));
|
h->atab = malloc(length(word));
|
||||||
|
if (h->atab == NULL)
|
||||||
|
errx(1, "Out of memory!");
|
||||||
for (s = word, t = h->atab; *s;)
|
for (s = word, t = h->atab; *s;)
|
||||||
*t++ = *s++ ^ '=';
|
*t++ = *s++ ^ '=';
|
||||||
*t = 0 ^ '=';
|
*t = 0 ^ '=';
|
||||||
|
Loading…
Reference in New Issue
Block a user