DEBUGFILES setup

Check getenv("DEBUGFILES") unconditionally during startup rather
than waiting until it's needed.

Might prevent the static analyzer from getting so aggravated.
Most likely not though, but should make debugpline() less fragile
if it gets called during a panic or a signal.
This commit is contained in:
PatR
2024-06-03 14:16:49 -07:00
parent 61d3cce4b8
commit 2ab477459f
2 changed files with 18 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 files.c $NHDT-Date: 1711213887 2024/03/23 17:11:27 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.397 $ */ /* NetHack 3.7 files.c $NHDT-Date: 1717449127 2024/06/03 21:12:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.399 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */ /*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -2796,10 +2796,9 @@ cnf_line_EXPLORERS(char *bufp)
staticfn boolean staticfn boolean
cnf_line_DEBUGFILES(char *bufp) cnf_line_DEBUGFILES(char *bufp)
{ {
/* if showdebug() has already been called (perhaps we've added /* might already have a vaule from getenv("DEBUGFILES");
some debugpline() calls to option processing) and has found if so, ignore this value from SYSCF */
a value for getenv("DEBUGFILES"), don't override that */ if (!sysopt.env_dbgfl) {
if (sysopt.env_dbgfl <= 0) {
if (sysopt.debugfiles) if (sysopt.debugfiles)
free((genericptr_t) sysopt.debugfiles); free((genericptr_t) sysopt.debugfiles);
sysopt.debugfiles = dupstr(bufp); sysopt.debugfiles = dupstr(bufp);
@@ -4523,20 +4522,6 @@ debugcore(const char *filename, boolean wildcards)
if (!filename || !*filename) if (!filename || !*filename)
return FALSE; /* sanity precaution */ return FALSE; /* sanity precaution */
if (sysopt.env_dbgfl == 0) {
/* check once for DEBUGFILES in the environment;
if found, it supersedes the sysconf value
[note: getenv() rather than nh_getenv() since a long value
is valid and doesn't pose any sort of overflow risk here] */
if ((p = getenv("DEBUGFILES")) != 0) {
if (sysopt.debugfiles)
free((genericptr_t) sysopt.debugfiles);
sysopt.debugfiles = dupstr(p);
sysopt.env_dbgfl = 1;
} else
sysopt.env_dbgfl = -1;
}
debugfiles = sysopt.debugfiles; debugfiles = sysopt.debugfiles;
/* usual case: sysopt.debugfiles will be empty */ /* usual case: sysopt.debugfiles will be empty */
if (!debugfiles || !*debugfiles) if (!debugfiles || !*debugfiles)

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 sys.c $NHDT-Date: 1693083254 2023/08/26 20:54:14 $ $NHDT-Branch: keni-crashweb2 $:$NHDT-Revision: 1.63 $ */ /* NetHack 3.7 sys.c $NHDT-Date: 1717449153 2024/06/03 21:12:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.64 $ */
/* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */ /* Copyright (c) Kenneth Lorber, Kensington, Maryland, 2008. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -20,6 +20,8 @@ struct sysopt sysopt;
void void
sys_early_init(void) sys_early_init(void)
{ {
const char *p;
sysopt.support = (char *) 0; sysopt.support = (char *) 0;
sysopt.recover = (char *) 0; sysopt.recover = (char *) 0;
#ifdef SYSCF #ifdef SYSCF
@@ -27,15 +29,22 @@ sys_early_init(void)
#else #else
sysopt.wizards = dupstr(WIZARD_NAME); sysopt.wizards = dupstr(WIZARD_NAME);
#endif #endif
if ((p = getenv("DEBUGFILES")) != 0) {
sysopt.debugfiles = dupstr(p);
sysopt.env_dbgfl = 1; /* prevent sysconf processing from overriding */
} else {
#if defined(SYSCF) || !defined(DEBUGFILES) #if defined(SYSCF) || !defined(DEBUGFILES)
sysopt.debugfiles = (char *) 0; sysopt.debugfiles = (char *) 0;
#else #else
sysopt.debugfiles = dupstr(DEBUGFILES); sysopt.debugfiles = dupstr(DEBUGFILES);
#endif #endif
sysopt.env_dbgfl = 0;
}
#ifdef DUMPLOG #ifdef DUMPLOG
sysopt.dumplogfile = (char *) 0; sysopt.dumplogfile = (char *) 0;
#endif #endif
sysopt.env_dbgfl = 0; /* haven't checked getenv("DEBUGFILES") yet */
sysopt.shellers = (char *) 0; sysopt.shellers = (char *) 0;
sysopt.explorers = (char *) 0; sysopt.explorers = (char *) 0;
sysopt.genericusers = (char *) 0; sysopt.genericusers = (char *) 0;
@@ -105,6 +114,7 @@ sysopt_release(void)
if (sysopt.debugfiles) if (sysopt.debugfiles)
free((genericptr_t) sysopt.debugfiles), free((genericptr_t) sysopt.debugfiles),
sysopt.debugfiles = (char *) 0; sysopt.debugfiles = (char *) 0;
sysopt.env_dbgfl = 0;
#ifdef DUMPLOG #ifdef DUMPLOG
if (sysopt.dumplogfile) if (sysopt.dumplogfile)
free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0; free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0;