summaryrefslogtreecommitdiff
path: root/games/worm/worm.c
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>1998-09-16 00:44:38 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>1998-09-16 00:44:38 +0000
commit11fe28977822e0d301e52c65e35c79866a757bf3 (patch)
tree0dad2d9fb94b4aec0fc2b56987fc3ee3e4a27f29 /games/worm/worm.c
parent8896bd95b7432af011cd98842289c9c1124a2dc6 (diff)
Make sure malloc() succeeds
Diffstat (limited to 'games/worm/worm.c')
-rw-r--r--games/worm/worm.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/games/worm/worm.c b/games/worm/worm.c
index 28d9f85aa4e..ccf1b1c7f4e 100644
--- a/games/worm/worm.c
+++ b/games/worm/worm.c
@@ -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()
{