Subject: bin/8080: [PATCH] Backgammon malloc checks
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 07/26/1999 11:15:29
>Number:         8080
>Category:       bin
>Synopsis:       [PATCH] Backgammon malloc checks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 26 10:20:01 1999
>Last-Modified:
>Originator:     Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD anoncvs of 1999-07-25
>Environment:
[
System: Linux decomino 2.2.10 #1 Mon Jun 14 07:48:53 UTC 1999 i686 unknown
Architecture: i686
]
>Description:

This adds a check for memory allocation failure to one place in
backgammon(6).  The use of write(2) for the message may seem odd, but
is used in another place in this game.  (Actually, a lot of
backgammon(6) could do with being substantially cleaned up.)

>How-To-Repeat:

>Fix:

diff -ruN backgammon/common_source/fancy.c backgammon+/common_source/fancy.c
--- backgammon/common_source/fancy.c	Wed Feb 10 17:08:06 1999
+++ backgammon+/common_source/fancy.c	Mon Jul 26 16:23:52 1999
@@ -733,5 +733,9 @@
 	if (LI < 24 || CO < 72 || !(CL && UP && ND))
 		return (0);
 	linect = (int *) calloc(LI + 1, sizeof(int));
+	if (linect == NULL) {
+		write(2, "\r\nOut of memory!\r\n", 18);
+		getout(0);
+	}
 	return (1);
 }
>Audit-Trail:
>Unformatted: