]> granicus.if.org Git - nethack/commitdiff
"Bad option line" formatting
authorPatR <rankin@nethack.org>
Sat, 5 Dec 2015 02:52:51 +0000 (18:52 -0800)
committerPatR <rankin@nethack.org>
Sat, 5 Dec 2015 02:52:51 +0000 (18:52 -0800)
Change
  |Bad option line:  "foo
  |"
to
  |Bad option line: "foo"
by stripping away the input line's newline before processing it.

(This doesn't address the PANICTRACE options processing issue.)

src/files.c

index 1ce0c872e158015b16edad1a52cf3ee31541280e..6a74de52ce51f0d47a4588c87a7cd76ce05d32b8 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 files.c $NHDT-Date: 1448323244 2015/11/24 00:00:44 $  $NHDT-Branch: master $:$NHDT-Revision: 1.190 $ */
+/* NetHack 3.6 files.c $NHDT-Date: 1449283964 2015/12/05 02:52:44 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.191 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2559,7 +2559,7 @@ read_config_file(filename, src)
 const char *filename;
 int src;
 {
-    char buf[4 * BUFSZ];
+    char buf[4 * BUFSZ], *p;
     FILE *fp;
     boolean rv = TRUE; /* assume successful parse */
 
@@ -2577,8 +2577,16 @@ line at this level.
 OR: Forbid multiline stuff for alternate config sources.
 */
 #endif
+        if ((p = index(buf, '\n')) != 0)
+            *p = '\0';
         if (!parse_config_line(fp, buf, src)) {
-            raw_printf("Bad option line:  \"%.50s\"", buf);
+            static const char badoptionline[] = "Bad option line: \"%s\"";
+
+            /* truncate buffer if it's long; this is actually conservative */
+            if (strlen(buf) > BUFSZ - sizeof badoptionline)
+                buf[BUFSZ - sizeof badoptionline] = '\0';
+
+            raw_printf(badoptionline, buf);
             wait_synch();
             rv = FALSE;
         }