From: downsj Date: Sun, 26 Jan 1997 08:00:52 +0000 (+0000) Subject: Check malloc() return value. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=74471cb56c7606efb643bba9429787d84f361ba4;p=openbsd Check malloc() return value. --- diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h index 301592f1d12..0ff22fac4cd 100644 --- a/games/gomoku/gomoku.h +++ b/games/gomoku/gomoku.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gomoku.h,v 1.2 1996/12/21 21:17:50 tholo Exp $ */ +/* $OpenBSD: gomoku.h,v 1.3 1997/01/26 08:00:52 downsj Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -299,6 +299,7 @@ extern void markcombo __P((struct combostr *)); extern void panic __P((char *)); extern int pickmove __P((int)); extern void printcombo __P((struct combostr *, char *)); +extern void qlog __P((char *)); extern void quit __P((int)); extern int readinput __P((FILE *)); extern void scanframes __P((int)); diff --git a/games/gomoku/main.c b/games/gomoku/main.c index d01bd99d819..c75dbd6b20f 100644 --- a/games/gomoku/main.c +++ b/games/gomoku/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.6 1997/01/15 23:40:49 millert Exp $ */ +/* $OpenBSD: main.c,v 1.7 1997/01/26 08:00:53 downsj Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -513,6 +513,20 @@ log(str) printf("%s\n", str); } +/* + * Deal with a fatal error. + */ +void +qlog(str) + char *str; +{ + dlog(str); + if (interactive) + beep(); + sleep(5); + quit(0); +} + /* ARGSUSED */ void quit(sig) diff --git a/games/gomoku/pickmove.c b/games/gomoku/pickmove.c index c0f5d53da16..2d955ec7011 100644 --- a/games/gomoku/pickmove.c +++ b/games/gomoku/pickmove.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pickmove.c,v 1.3 1996/12/21 21:17:52 tholo Exp $ */ +/* $OpenBSD: pickmove.c,v 1.4 1997/01/26 08:00:54 downsj Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -472,6 +472,8 @@ makecombo2(ocbp, osp, off, s) /* make a new combo! */ ncbp = (struct combostr *)malloc(sizeof(struct combostr) + 2 * sizeof(struct combostr *)); + if (ncbp == (struct combostr *)NULL) + qlog("Memory allocation failure."); scbpp = (struct combostr **)(ncbp + 1); fcbp = fsp->s_frame[r]; if (ocbp < fcbp) { @@ -711,6 +713,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 == (struct combostr *)NULL) + qlog("Memory allocation failure."); scbpp = (struct combostr **)(ncbp + 1); if (sortcombo(scbpp, (struct combostr **)(cbp + 1), ocbp)) { free(ncbp); @@ -910,6 +914,8 @@ makeempty(ocbp) /* add the combo to the list of empty spots */ nep = (struct elist *)malloc(sizeof(struct elist)); + if (nep == (struct elist *)NULL) + qlog("Memory allocation failure."); nep->e_combo = ocbp; nep->e_off = s; nep->e_frameindex = i;