From: nhmall Date: Sat, 28 Apr 2018 21:22:21 +0000 (-0400) Subject: last line of config file wasn't heeded if newline was missing X-Git-Tag: NetHack-3.6.2_Released~286 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e5c41401fbe4ff1ccdc6989b4701ee7f093ee7c;p=nethack last line of config file wasn't heeded if newline was missing --- diff --git a/doc/fixes36.2 b/doc/fixes36.2 index df24cfbf4..ca45e5826 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -7,6 +7,7 @@ shift to the next major release. General Fixes and Modified Features ----------------------------------- +last line of config file wasn't being heeded if it had no newline Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository diff --git a/src/files.c b/src/files.c index e73b27699..8a490d09e 100644 --- a/src/files.c +++ b/src/files.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 files.c $NHDT-Date: 1524413723 2018/04/22 16:15:23 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.235 $ */ +/* NetHack 3.6 files.c $NHDT-Date: 1524950534 2018/04/28 21:22:14 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.238 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3022,26 +3022,34 @@ boolean FDECL((*proc), (char *)); char *ep; boolean skip = FALSE, morelines = FALSE; char *buf = (char *) 0; + size_t inbufsz = sizeof inbuf; free_config_sections(); - while (fgets(inbuf, (int) (sizeof inbuf), fp)) { + while (fgets(inbuf, (int) inbufsz, fp)) { ep = index(inbuf, '\n'); if (skip) { /* in case previous line was too long */ if (ep) skip = FALSE; /* found newline; next line is normal */ } else { - if (!ep) { - config_error_add("Line too long, skipping"); - skip = TRUE; /* newline missing; discard next fgets */ + if (!ep) { /* newline missing */ + if (strlen(inbuf) < (inbufsz - 2)) { + /* likely the last line of file is just + missing a newline; process it anyway */ + ep = eos(inbuf); + } else { + config_error_add("Line too long, skipping"); + skip = TRUE; /* discard next fgets */ + } } else { + *ep = '\0'; /* remove newline */ + } + if (ep) { char *tmpbuf = (char *) 0; int len; boolean ignoreline = FALSE; boolean oldline = FALSE; - *ep = '\0'; /* remove newline */ - /* line continuation (trailing '\') */ morelines = (--ep >= inbuf && *ep == '\\'); if (morelines)