summaryrefslogtreecommitdiffstats
path: root/sail
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2009-03-02 07:21:56 +0000
committerdholland <dholland@NetBSD.org>2009-03-02 07:21:56 +0000
commitcb23d290fb00d766334d734193c06058584163b4 (patch)
tree51b6fe8827f28df7763c1c68d8a1276c0b7628b1 /sail
parent943621f8a6eb8a69bef1457f68be5fc43c998212 (diff)
downloadbsdgames-darwin-cb23d290fb00d766334d734193c06058584163b4.tar.gz
bsdgames-darwin-cb23d290fb00d766334d734193c06058584163b4.tar.zst
bsdgames-darwin-cb23d290fb00d766334d734193c06058584163b4.zip
Check for failure of fgets when reading the captain's name, and don't
allow it to be empty. From OpenBSD.
Diffstat (limited to 'sail')
-rw-r--r--sail/pl_main.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sail/pl_main.c b/sail/pl_main.c
index 17a1c05e..bb373f55 100644
--- a/sail/pl_main.c
+++ b/sail/pl_main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pl_main.c,v 1.17 2006/04/20 10:57:26 drochner Exp $ */
+/* $NetBSD: pl_main.c,v 1.18 2009/03/02 07:21:56 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pl_main.c,v 1.17 2006/04/20 10:57:26 drochner Exp $");
+__RCSID("$NetBSD: pl_main.c,v 1.18 2009/03/02 07:21:56 dholland Exp $");
#endif
#endif /* not lint */
@@ -205,8 +205,9 @@ reprint:
else {
printf("Your name, Captain? ");
fflush(stdout);
- fgets(captain, sizeof captain, stdin);
- if (!*captain)
+ if (fgets(captain, sizeof captain, stdin) == NULL)
+ strcpy(captain, "no name");
+ else if (*captain == '\0' || *captain == '\n')
strcpy(captain, "no name");
else
captain[strlen(captain) - 1] = '\0';