Subject: bin/8056: [PATCH] Atc memory allocation checks
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 07/24/1999 03:51:30
>Number:         8056
>Category:       bin
>Synopsis:       [PATCH] Atc memory allocation 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:   Sat Jul 24 03:50:01 1999
>Last-Modified:
>Originator:     Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1999-07-22
>Environment:
[
System: Linux decomino 2.2.10 #1 Mon Jun 14 07:48:53 UTC 1999 i686 unknown
Architecture: i686
]
>Description:

This patch makes atc(6) check for memory allocation failure.

>How-To-Repeat:

>Fix:

diff -ruN atc/graphics.c atc+/graphics.c
--- atc/graphics.c	Wed Nov 11 12:11:25 1998
+++ atc+/graphics.c	Sat Jul 24 10:15:02 1999
@@ -401,8 +401,12 @@
 
 	wmove(input, 0, 0);
 	wclrtobot(input);
-	wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
-		name(p), s);
+	/* p may be NULL if we ran out of memory */
+	if (p == NULL)
+		wprintw(input, "%s\n\nHit space for top players list...", s);
+	else
+		wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
+			name(p), s);
 	wrefresh(input);
 	fflush(stdout);
 	while ((c = getchar()) != EOF && c != ' ')
diff -ruN atc/update.c atc+/update.c
--- atc/update.c	Wed Nov 11 12:11:26 1998
+++ atc+/update.c	Sat Jul 24 10:15:31 1999
@@ -365,6 +365,8 @@
 	p.plane_no = pnum;
 
 	pp = newplane();
+	if (pp == NULL)
+		loser(pp, "Out of memory!");
 	memcpy(pp, &p, sizeof (p));
 
 	if (pp->orig_type == T_AIRPORT)
>Audit-Trail:
>Unformatted: