]> granicus.if.org Git - nethack/commitdiff
last line of config file wasn't heeded if newline was missing
authornhmall <nhmall@nethack.org>
Sat, 28 Apr 2018 21:22:21 +0000 (17:22 -0400)
committernhmall <nhmall@nethack.org>
Sat, 28 Apr 2018 21:22:21 +0000 (17:22 -0400)
doc/fixes36.2
src/files.c

index df24cfbf4c46c5f83307d2efe2609a98d778f470..ca45e58263d9e8f6f927d1db6548ea42f25d59a6 100644 (file)
@@ -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
index e73b27699074a9b8be9271bece0f222420142d2b..8a490d09e76f524620b1eee5c4aa7c6576d4d400 100644 (file)
@@ -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)