]> granicus.if.org Git - nethack/commitdiff
paniclog fix
authorPatR <rankin@nethack.org>
Wed, 1 Jun 2022 07:37:52 +0000 (00:37 -0700)
committerPatR <rankin@nethack.org>
Wed, 1 Jun 2022 07:37:52 +0000 (00:37 -0700)
Writing lua warnings to paniclog (coming soon; tested without the
garbage collection fix in order to have test data) could crash on
the last pair.  Those are written after the 'nomakedefs' structure
had been freed so version_string was Null.

The NAO PANICLOG_FMT2 code triggered a warning about the test for
g.plname; it is array so will never be Null.

src/files.c
src/version.c

index 8032b52b04dc1b7f1bf7cc27251bb527ce842558..fba7166600e53dd9499d22071cef5b378c7c2784 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 files.c $NHDT-Date: 1646314650 2022/03/03 13:37:30 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.346 $ */
+/* NetHack 3.7 files.c $NHDT-Date: 1654069053 2022/06/01 07:37:33 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.351 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -3616,12 +3616,12 @@ check_recordfile(const char *dir UNUSED_if_not_OS2_CODEVIEW)
 
 /*ARGSUSED*/
 void
-paniclog(const char *type,   /* panic, impossible, trickery */
-         const char *reason) /* explanation */
+paniclog(
+    const char *type,   /* panic, impossible, trickery, [lua] */
+    const char *reason) /* explanation */
 {
 #ifdef PANICLOG
     FILE *lfile;
-    char buf[BUFSZ];
 
     if (!g.program_state.in_paniclog) {
         g.program_state.in_paniclog = 1;
@@ -3629,9 +3629,10 @@ paniclog(const char *type,   /* panic, impossible, trickery */
         if (lfile) {
 #ifdef PANICLOG_FMT2
             (void) fprintf(lfile, "%ld %s: %s %s\n",
-                           ubirthday, (g.plname ? g.plname : "(none)"),
+                           ubirthday, (g.plname[0] ? g.plname : "(none)"),
                            type, reason);
 #else
+            char buf[BUFSZ];
             time_t now = getnow();
             int uid = getuid();
             char playmode = wizard ? 'D' : discover ? 'X' : '-';
index 19167ad137104737b8a13dc96c6e6e70a380b231..1652f10fac6116b09d964d984377210e415aad5e 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 version.c       $NHDT-Date: 1651297024 2022/04/30 05:37:04 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.88 $ */
+/* NetHack 3.7 version.c       $NHDT-Date: 1654069065 2022/06/01 07:37:45 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.91 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2018. */
 /* NetHack may be freely redistributed.  See license for details. */
 #define OPTIONS_AT_RUNTIME
 #endif
 
+extern char *mdlib_version_string(char *, const char *);
 static void insert_rtoption(char *);
 
 /* fill buffer with short version (so caller can avoid including date.h) */
 char *
 version_string(char *buf, size_t bufsz)
 {
-    Snprintf(buf, bufsz, "%s", nomakedefs.version_string);
+    Snprintf(buf, bufsz, "%s",
+             ((nomakedefs.version_string && nomakedefs.version_string[0])
+              ? nomakedefs.version_string
+              /* in case we try to write a paniclog entry after releasing
+                 the 'nomakedefs' data */
+              : mdlib_version_string(buf, ".")));
     return buf;
 }