From 638c095d5cf47282d99189e1425435a0763a369b Mon Sep 17 00:00:00 2001 From: hubertf Date: Wed, 10 Feb 1999 00:11:28 +0000 Subject: The game adventure(6) handles EOF on standard input rather ungracefully. The patch, derived from OpenBSD, improves this handling. Sent in in PR 6556 by Joseph Myers . --- adventure/wizard.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'adventure/wizard.c') diff --git a/adventure/wizard.c b/adventure/wizard.c index 5df1b08d..94de0530 100644 --- a/adventure/wizard.c +++ b/adventure/wizard.c @@ -1,4 +1,4 @@ -/* $NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $ */ +/* $NetBSD: wizard.c,v 1.9 1999/02/10 00:11:28 hubertf Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93"; #else -__RCSID("$NetBSD: wizard.c,v 1.8 1998/08/24 22:07:37 hubertf Exp $"); +__RCSID("$NetBSD: wizard.c,v 1.9 1999/02/10 00:11:28 hubertf Exp $"); #endif #endif /* not lint */ @@ -136,9 +136,14 @@ ciao() char fname[80]; printf("What would you like to call the saved version?\n"); - for (c = fname;; c++) - if ((*c = getchar()) == '\n') + /* XXX - should use fgetln to avoid arbitrary limit */ + for (c = fname; c < fname + sizeof fname - 1; c++) { + int ch; + ch = getchar(); + if (ch == '\n' || ch == EOF) break; + *c = ch; + } *c = 0; if (save(fname) != 0) return; /* Save failed */ -- cgit v1.2.3