From 540e37d7ff8085f7cf6abac27b5f298a50d1af1e Mon Sep 17 00:00:00 2001 From: dholland Date: Sun, 24 Feb 2008 06:12:49 +0000 Subject: Don't crash if we're asked to restore from /dev/null. (woops) --- monop/execute.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/monop/execute.c b/monop/execute.c index b8208fcc..6b5334a3 100644 --- a/monop/execute.c +++ b/monop/execute.c @@ -1,4 +1,4 @@ -/* $NetBSD: execute.c,v 1.20 2008/02/24 06:03:35 dholland Exp $ */ +/* $NetBSD: execute.c,v 1.21 2008/02/24 06:12:49 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: execute.c,v 1.20 2008/02/24 06:03:35 dholland Exp $"); +__RCSID("$NetBSD: execute.c,v 1.21 2008/02/24 06:12:49 dholland Exp $"); #endif #endif /* not lint */ @@ -362,6 +362,7 @@ rest_f(const char *file) char xbuf[80]; STAT sbuf; char readbuf[512]; + int ret = 0; inf = fopen(file, "r"); if (inf == NULL) { @@ -389,11 +390,13 @@ rest_f(const char *file) sp = strchr(readbuf, '\n'); if (sp == NULL) { printf("file is corrupt: long lines.\n"); + ret = -1; break; } *sp = '\0'; if (restore_parseline(readbuf)) { + ret = -1; break; } } @@ -402,8 +405,16 @@ rest_f(const char *file) warnx("%s: read error", file); fclose(inf); + if (ret < 0) + return -1; + name_list[num_play] = "done"; + if (play == NULL || cur_p == NULL || num_play < 2) { + printf("save file is incomplete.\n"); + return -1; + } + /* * We could at this point crosscheck the following: * - there are only two GOJF cards floating around -- cgit v1.2.3-56-ge451