Subject: bin/6147: [PATCH] Adventure exit status
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 09/13/1998 12:42:10
>Number:         6147
>Category:       bin
>Synopsis:       [PATCH] Adventure exit status
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 13 07:05:01 1998
>Last-Modified:
>Originator:     Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-09-13
>Environment:
[
System: Linux octomino 2.0.35 #1 Wed Aug 12 15:54:21 UTC 1998 i586 unknown
Architecture: i586
]
>Description:

Under certain error conditions, mostly internal errors, adventure(6)
exits with a successful exit status when it should exit with an error
status.  The patch below fixes this, but maybe you also want to change
the error messages to make it clear that these are internal errors and
should be reported as bugs if reproducible.

>How-To-Repeat:

>Fix:

diff -ruN adventure/io.c adventure+/io.c
--- adventure/io.c	Sun Sep 13 11:05:31 1998
+++ adventure+/io.c	Sun Sep 13 12:30:36 1998
@@ -49,6 +49,7 @@
 
 /*      Re-coding of advent in C: file i/o and user i/o                 */
 
+#include <err.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -297,8 +298,7 @@
 				break;
 			case 6:/* random messages              */
 				if (oldloc > RTXSIZ) {
-					printf("Too many random msgs\n");
-					exit(0);
+					errx(1, "Too many random msgs");
 				}
 				rtext[oldloc].seekadr = seekhere;
 				rtext[oldloc].txtlen = maystart - seekstart;
@@ -310,15 +310,13 @@
 				break;
 			case 12:	/* magic messages               */
 				if (oldloc > MAGSIZ) {
-					printf("Too many magic msgs\n");
-					exit(0);
+					errx(1, "Too many magic msgs");
 				}
 				mtext[oldloc].seekadr = seekhere;
 				mtext[oldloc].txtlen = maystart - seekstart;
 				break;
 			default:
-				printf("rdesc called with bad section\n");
-				exit(0);
+				errx(1, "rdesc called with bad section");
 			}
 			seekhere += maystart - seekstart;
 		}
diff -ruN adventure/main.c adventure+/main.c
--- adventure/main.c	Sat Sep 12 11:04:36 1998
+++ adventure+/main.c	Sun Sep 13 12:31:52 1998
@@ -90,10 +90,10 @@
 			unlink(argv[1]);	/* Don't re-use the save */
 			goto l8;		/* Get where we're going */
 		case 1:				/* Couldn't open it */
-			exit(0);		/* So give up */
+			exit(1);		/* So give up */
 		case 2:				/* Oops -- file was altered */
 			rspeak(202);		/* You dissolve */
-			exit(0);	/* File could be non-adventure */
+			exit(1);	/* File could be non-adventure */
 		}			/* So don't unlink it. */
 	}
 	startup();			/* prepare for a user */
@@ -277,8 +277,7 @@
 		case 4:
 			goto l2010;
 		default:
-			printf("Error 22\n");
-			exit(0);
+			bug(22);
 		}
 
 l8:
diff -ruN adventure/subr.c adventure+/subr.c
--- adventure/subr.c	Tue Aug 25 11:05:17 1998
+++ adventure+/subr.c	Sun Sep 13 12:32:14 1998
@@ -501,7 +501,7 @@
 	int     n;
 {
 	printf("Please tell jim@rand.org that fatal bug %d happened.\n", n);
-	exit(0);
+	exit(1);
 }
 
 
diff -ruN adventure/vocab.c adventure+/vocab.c
--- adventure/vocab.c	Sun Sep 13 11:05:31 1998
+++ adventure+/vocab.c	Sun Sep 13 12:33:04 1998
@@ -49,6 +49,7 @@
 
 /*      Re-coding of advent in C: data structure routines               */
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "hdr.h"
@@ -182,8 +183,7 @@
 			return (h->val);
 		default:	/* looking up known word        */
 			if (h->val == 0) {
-				printf("Unable to find %s in vocab\n", word);
-				exit(0);
+				errx(1, "Unable to find %s in vocab", word);
 			}
 			for (s = word, t = h->atab; *t ^ '=';)
 				if ((*s++ ^ '=') != *t++)
@@ -196,8 +196,7 @@
 
 exitloop2:			/* hashed entry does not match  */
 		if (adr + 1 == hash || (adr == HTSIZE && hash == 0)) {
-			printf("Hash table overflow\n");
-			exit(0);
+			errx(1, "Hash table overflow");
 		}
 	}
 }
>Audit-Trail:
>Unformatted: