From: PatR Date: Wed, 1 Jun 2022 07:37:52 +0000 (-0700) Subject: paniclog fix X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7080a6183e1c88ca412de3391b935d454f0c184;p=nethack paniclog fix 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. --- diff --git a/src/files.c b/src/files.c index 8032b52b0..fba716660 100644 --- a/src/files.c +++ b/src/files.c @@ -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' : '-'; diff --git a/src/version.c b/src/version.c index 19167ad13..1652f10fa 100644 --- a/src/version.c +++ b/src/version.c @@ -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. */ @@ -10,13 +10,19 @@ #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; }