Check for failure of malloc() and calloc() at various places in the games.
This commit is contained in:
parent
6b9aae738e
commit
a9c7f9b096
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pickmove.c,v 1.7 1999/09/08 21:45:27 jsm Exp $ */
|
||||
/* $NetBSD: pickmove.c,v 1.8 1999/09/09 17:27:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: pickmove.c,v 1.7 1999/09/08 21:45:27 jsm Exp $");
|
||||
__RCSID("$NetBSD: pickmove.c,v 1.8 1999/09/09 17:27:58 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -479,6 +479,8 @@ makecombo2(ocbp, osp, off, s)
|
||||
/* make a new combo! */
|
||||
ncbp = (struct combostr *)malloc(sizeof(struct combostr) +
|
||||
2 * sizeof(struct combostr *));
|
||||
if (ncbp == NULL)
|
||||
panic("Out of memory!");
|
||||
scbpp = (struct combostr **)(ncbp + 1);
|
||||
fcbp = fsp->s_frame[r];
|
||||
if (ocbp < fcbp) {
|
||||
@ -718,6 +720,8 @@ makecombo(ocbp, osp, off, s)
|
||||
/* make a new combo! */
|
||||
ncbp = (struct combostr *)malloc(sizeof(struct combostr) +
|
||||
(cbp->c_nframes + 1) * sizeof(struct combostr *));
|
||||
if (ncbp == NULL)
|
||||
panic("Out of memory!");
|
||||
scbpp = (struct combostr **)(ncbp + 1);
|
||||
if (sortcombo(scbpp, (struct combostr **)(cbp + 1), ocbp)) {
|
||||
free(ncbp);
|
||||
@ -918,6 +922,8 @@ makeempty(ocbp)
|
||||
|
||||
/* add the combo to the list of empty spots */
|
||||
nep = (struct elist *)malloc(sizeof(struct elist));
|
||||
if (nep == NULL)
|
||||
panic("Out of memory!");
|
||||
nep->e_combo = ocbp;
|
||||
nep->e_off = s;
|
||||
nep->e_frameindex = i;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cards.c,v 1.9 1999/09/08 21:57:18 jsm Exp $ */
|
||||
/* $NetBSD: cards.c,v 1.10 1999/09/09 17:27:58 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: cards.c,v 1.9 1999/09/08 21:57:18 jsm Exp $");
|
||||
__RCSID("$NetBSD: cards.c,v 1.10 1999/09/09 17:27:58 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -102,6 +102,8 @@ set_up(dp)
|
||||
int i;
|
||||
|
||||
dp->offsets = (off_t *) calloc(sizeof (off_t), dp->num_cards);
|
||||
if (dp->offsets == NULL)
|
||||
errx(1, "out of memory");
|
||||
if (fread(dp->offsets, sizeof(off_t), dp->num_cards, deckf) !=
|
||||
dp->num_cards) {
|
||||
perror(cardfile);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: initdeck.c,v 1.9 1999/09/08 21:57:18 jsm Exp $ */
|
||||
/* $NetBSD: initdeck.c,v 1.10 1999/09/09 17:27:59 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,10 +43,11 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)initdeck.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: initdeck.c,v 1.9 1999/09/08 21:57:18 jsm Exp $");
|
||||
__RCSID("$NetBSD: initdeck.c,v 1.10 1999/09/09 17:27:59 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@ -101,6 +102,8 @@ main(ac, av)
|
||||
*/
|
||||
CC_D.offsets = (off_t *)calloc(CC_D.num_cards + 1, sizeof (off_t));
|
||||
CH_D.offsets = (off_t *)calloc(CH_D.num_cards + 1, sizeof (off_t));
|
||||
if (CC_D.offsets == NULL || CH_D.offsets == NULL)
|
||||
errx(1, "out of memory");
|
||||
fseek(inf, 0L, SEEK_SET);
|
||||
if ((outf = fopen(outfile, "w")) == NULL) {
|
||||
perror(outfile);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: monop.c,v 1.7 1999/09/08 21:45:28 jsm Exp $ */
|
||||
/* $NetBSD: monop.c,v 1.8 1999/09/09 17:27:59 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: monop.c,v 1.7 1999/09/08 21:45:28 jsm Exp $");
|
||||
__RCSID("$NetBSD: monop.c,v 1.8 1999/09/09 17:27:59 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -116,6 +116,8 @@ blew_it:
|
||||
break;
|
||||
}
|
||||
cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
|
||||
if (play == NULL)
|
||||
errx(1, "out of memory");
|
||||
for (i = 0; i < num_play; i++) {
|
||||
over:
|
||||
printf("Player %d's name: ", i + 1);
|
||||
@ -124,7 +126,10 @@ over:
|
||||
if (sp == buf)
|
||||
goto over;
|
||||
*sp++ = '\0';
|
||||
strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
|
||||
name_list[i] = play[i].name = (char *)calloc(1, sp - buf);
|
||||
if (name_list[i] == NULL)
|
||||
errx(1, "out of memory");
|
||||
strcpy(play[i].name, buf);
|
||||
play[i].money = 1500;
|
||||
}
|
||||
name_list[i++] = "done";
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: monop.h,v 1.8 1999/09/08 21:17:52 jsm Exp $ */
|
||||
/* $NetBSD: monop.h,v 1.9 1999/09/09 17:27:59 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -35,6 +35,7 @@
|
||||
* @(#)monop.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: prop.c,v 1.5 1999/08/21 10:40:04 simonb Exp $ */
|
||||
/* $NetBSD: prop.c,v 1.6 1999/09/09 17:27:59 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: prop.c,v 1.5 1999/08/21 10:40:04 simonb Exp $");
|
||||
__RCSID("$NetBSD: prop.c,v 1.6 1999/09/09 17:27:59 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -75,6 +75,8 @@ add_list(plr, head, op_sqr)
|
||||
OWN *op;
|
||||
|
||||
op = (OWN *)calloc(1, sizeof (OWN));
|
||||
if (op == NULL)
|
||||
errx(1, "out of memory");
|
||||
op->sqr = &board[op_sqr];
|
||||
val = value(op->sqr);
|
||||
last_tp = NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: init.c,v 1.8 1999/09/08 21:45:30 jsm Exp $ */
|
||||
/* $NetBSD: init.c,v 1.9 1999/09/09 17:27:59 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: init.c,v 1.8 1999/09/08 21:45:30 jsm Exp $");
|
||||
__RCSID("$NetBSD: init.c,v 1.9 1999/09/09 17:27:59 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -332,6 +332,8 @@ env_get_value(s, e, add_blank)
|
||||
}
|
||||
}
|
||||
*s = md_malloc(MAX_OPT_LEN + 2);
|
||||
if (*s == NULL)
|
||||
clean_up("out of memory");
|
||||
(void) strncpy(*s, t, i);
|
||||
if (add_blank) {
|
||||
(*s)[i++] = ' ';
|
||||
@ -346,6 +348,8 @@ init_str(str, dflt)
|
||||
{
|
||||
if (!(*str)) {
|
||||
*str = md_malloc(MAX_OPT_LEN + 2);
|
||||
if (*str == NULL)
|
||||
clean_up("out of memory");
|
||||
(void) strcpy(*str, dflt);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: snscore.c,v 1.9 1999/09/08 21:18:00 jsm Exp $ */
|
||||
/* $NetBSD: snscore.c,v 1.10 1999/09/09 17:28:00 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)snscore.c 8.1 (Berkeley) 7/19/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: snscore.c,v 1.9 1999/09/08 21:18:00 jsm Exp $");
|
||||
__RCSID("$NetBSD: snscore.c,v 1.10 1999/09/09 17:28:00 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -98,8 +98,9 @@ main()
|
||||
if (p == NULL)
|
||||
continue;
|
||||
q = p -> pw_name;
|
||||
players[noplayers].name = malloc(strlen(q) + 1);
|
||||
strcpy(players[noplayers].name, q);
|
||||
players[noplayers].name = strdup(q);
|
||||
if (players[noplayers].name == NULL)
|
||||
errx(1, "out of memory");
|
||||
noplayers++;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: worm.c,v 1.14 1999/09/08 21:45:34 jsm Exp $ */
|
||||
/* $NetBSD: worm.c,v 1.15 1999/09/09 17:28:00 jsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: worm.c,v 1.14 1999/09/08 21:45:34 jsm Exp $");
|
||||
__RCSID("$NetBSD: worm.c,v 1.15 1999/09/09 17:28:00 jsm Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -54,6 +54,7 @@ __RCSID("$NetBSD: worm.c,v 1.14 1999/09/08 21:45:34 jsm Exp $");
|
||||
|
||||
#include <ctype.h>
|
||||
#include <curses.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
@ -151,12 +152,16 @@ life()
|
||||
|
||||
np = NULL;
|
||||
head = newlink();
|
||||
if (head == NULL)
|
||||
errx(1, "out of memory");
|
||||
head->x = start_len+2;
|
||||
head->y = 12;
|
||||
head->next = NULL;
|
||||
display(head, HEAD);
|
||||
for (i = 0, bp = head; i < start_len; i++, bp = np) {
|
||||
np = newlink();
|
||||
if (np == NULL)
|
||||
errx(1, "out of memory");
|
||||
np->next = bp;
|
||||
bp->prev = np;
|
||||
np->x = bp->x - 1;
|
||||
@ -277,6 +282,8 @@ process(ch)
|
||||
}
|
||||
else if(ch != ' ') crash();
|
||||
nh = newlink();
|
||||
if (nh == NULL)
|
||||
errx(1, "out of memory");
|
||||
nh->next = NULL;
|
||||
nh->prev = head;
|
||||
head->next = nh;
|
||||
|
Loading…
Reference in New Issue
Block a user