mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Make sure malloc() succeeds
This commit is contained in:
parent
eecc1014c5
commit
5f9f88f998
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: init.c,v 1.4 1998/08/22 08:55:27 pjanzen Exp $ */
|
||||
/* $OpenBSD: init.c,v 1.5 1998/09/16 00:44:36 pjanzen Exp $ */
|
||||
/* $NetBSD: init.c,v 1.4 1995/04/28 23:49:19 mycroft Exp $ */
|
||||
|
||||
/*
|
||||
@ -41,7 +41,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: init.c,v 1.4 1998/08/22 08:55:27 pjanzen Exp $";
|
||||
static char rcsid[] = "$OpenBSD: init.c,v 1.5 1998/09/16 00:44:36 pjanzen Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -57,6 +57,7 @@ static char rcsid[] = "$OpenBSD: init.c,v 1.4 1998/08/22 08:55:27 pjanzen Exp $"
|
||||
*
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include "rogue.h"
|
||||
|
||||
char login_name[MAX_OPT_LEN];
|
||||
@ -334,7 +335,8 @@ env_get_value(s, e, add_blank)
|
||||
break;
|
||||
}
|
||||
}
|
||||
*s = md_malloc(MAX_OPT_LEN + 2);
|
||||
if (!(*s = md_malloc(MAX_OPT_LEN + 2)))
|
||||
errx(1, "malloc failure");
|
||||
(void) strncpy(*s, t, i);
|
||||
if (add_blank) {
|
||||
(*s)[i++] = ' ';
|
||||
@ -347,7 +349,8 @@ init_str(str, dflt)
|
||||
char **str, *dflt;
|
||||
{
|
||||
if (!(*str)) {
|
||||
*str = md_malloc(MAX_OPT_LEN + 2);
|
||||
if (!(*str = md_malloc(MAX_OPT_LEN + 2)))
|
||||
errx(1, "malloc failure");
|
||||
(void) strcpy(*str, dflt);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: worm.c,v 1.6 1998/08/19 07:42:21 pjanzen Exp $ */
|
||||
/* $OpenBSD: worm.c,v 1.7 1998/09/16 00:44:37 pjanzen Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,7 +43,7 @@ static char copyright[] =
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: worm.c,v 1.6 1998/08/19 07:42:21 pjanzen Exp $";
|
||||
static char rcsid[] = "$OpenBSD: worm.c,v 1.7 1998/09/16 00:44:37 pjanzen Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -54,12 +54,12 @@ static char rcsid[] = "$OpenBSD: worm.c,v 1.6 1998/08/19 07:42:21 pjanzen Exp $"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <curses.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define newlink() (struct body *) malloc(sizeof (struct body));
|
||||
#define HEAD '@'
|
||||
#define BODY 'o'
|
||||
#define LENGTH 7
|
||||
@ -87,6 +87,7 @@ void display __P((struct body *, char));
|
||||
void leave __P((int));
|
||||
void life __P((void));
|
||||
void newpos __P((struct body *));
|
||||
struct body *newlink __P((void));
|
||||
void process __P((char));
|
||||
void prize __P((void));
|
||||
int rnd __P((int));
|
||||
@ -163,7 +164,7 @@ life()
|
||||
np = newlink();
|
||||
np->next = bp;
|
||||
bp->prev = np;
|
||||
if (((bp->x <= 2) && (j == 1)) || ((bp->x >= COLS-4)) && (j == -1)) {
|
||||
if (((bp->x <= 2) && (j == 1)) || ((bp->x >= COLS-4) && (j == -1))) {
|
||||
j *= -1;
|
||||
np->x = bp->x;
|
||||
np->y = bp->y + 1;
|
||||
@ -296,6 +297,18 @@ process(ch)
|
||||
alarm(1);
|
||||
}
|
||||
|
||||
struct body *
|
||||
newlink()
|
||||
{
|
||||
struct body *tmp;
|
||||
|
||||
if ((tmp = (struct body *) malloc(sizeof (struct body))) == NULL) {
|
||||
endwin();
|
||||
errx(1, "out of memory");
|
||||
}
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
void
|
||||
crash()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user