store lastch to an int so that EOF is handled properly.

This commit is contained in:
christos 2014-09-06 12:18:49 +00:00
parent 69b6b2b0d0
commit 734041fc2a

View File

@ -1,4 +1,4 @@
/* $NetBSD: crontab.c,v 1.9 2014/09/05 21:32:37 christos Exp $ */
/* $NetBSD: crontab.c,v 1.10 2014/09/06 12:18:49 christos Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@ -25,7 +25,7 @@
#if 0
static char rcsid[] = "Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp";
#else
__RCSID("$NetBSD: crontab.c,v 1.9 2014/09/05 21:32:37 christos Exp $");
__RCSID("$NetBSD: crontab.c,v 1.10 2014/09/06 12:18:49 christos Exp $");
#endif
#endif
@ -560,7 +560,8 @@ edit_cmd(void) {
*/
static int
replace_cmd(void) {
char n[MAX_FNAME], n2[MAX_FNAME], envstr[MAX_ENVSTR], lastch;
char n[MAX_FNAME], n2[MAX_FNAME], envstr[MAX_ENVSTR];
int lastch;
FILE *tmp, *fmaxtabsize;
int ch, eof, fd;
int error = 0;
@ -638,7 +639,7 @@ replace_cmd(void) {
*/
(void)fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
(void)fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
(void)fprintf(tmp, "# (Cron version %s -- %s)\n", CRON_VERSION, "$NetBSD: crontab.c,v 1.9 2014/09/05 21:32:37 christos Exp $");
(void)fprintf(tmp, "# (Cron version %s -- %s)\n", CRON_VERSION, "$NetBSD: crontab.c,v 1.10 2014/09/06 12:18:49 christos Exp $");
/* copy the crontab to the tmp
*/
@ -648,7 +649,7 @@ replace_cmd(void) {
while (EOF != (ch = get_char(NewCrontab)))
(void)putc(lastch = (char)ch, tmp);
if (lastch != (char)EOF && lastch != '\n') {
if (lastch != EOF && lastch != '\n') {
warnx("missing trailing newline in `%s'", Filename);
error = -1;
goto done;