From: PatR Date: Wed, 17 Mar 2021 01:45:56 +0000 (-0700) Subject: fix pull request #471 - error message segfault X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a203ff9feb34920e40a235b0d2dc08c389591032;p=nethack fix pull request #471 - error message segfault for invalid 'O' values when option error messages are issued after theme rooms have left iflags.in_lua set. The pull request just turned the flag off but lua code turns back on and off after that for other dungeon levels. nhlua probably shouldn't be sharing the same error routine as options processing, or at least it should toggle the flag on and off at need instead of pretending that it can be global. Fixes #471 --- diff --git a/doc/fixes37.0 b/doc/fixes37.0 index c0271d18b..1dfbf18c2 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -547,6 +547,8 @@ engraving with non-blade dulled the weapon anyway (pr #464) 'sortdiscoveries:s' had a spurious generic header shown at the start of the last class if there were any artifacts or unique items discovered loss of saddle by opening magic left hero mounted on unsaddled steed +avoid segfault during error reporting for bad 'O' value(s) after theme rooms + have been initialized, leaving iflags.in_lua set curses: 'msg_window' option wasn't functional for curses unless the binary also included tty support diff --git a/src/files.c b/src/files.c index c488ae93c..58ede76f8 100644 --- a/src/files.c +++ b/src/files.c @@ -2899,7 +2899,8 @@ config_erradd(const char *buf) buf = "Unknown error"; if (iflags.in_lua) { - struct _config_error_errmsg *dat = (struct _config_error_errmsg *) alloc(sizeof (struct _config_error_errmsg)); + struct _config_error_errmsg *dat + = (struct _config_error_errmsg *) alloc(sizeof *dat); dat->next = config_error_msg; dat->line_num = config_error_data->line_num; diff --git a/src/mklev.c b/src/mklev.c index dde1b8165..dc606f7ad 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -277,6 +277,8 @@ makerooms(void) } else { /* success; save state for this dungeon branch */ g.luathemes[u.uz.dnum] = (genericptr_t) themes; + /* keep themes context, so not 'nhl_done(themes);' */ + iflags.in_lua = FALSE; /* can affect error messages */ } } if (!themes) /* don't try again when making next level */ @@ -299,11 +301,11 @@ makerooms(void) } } else { if (themes) { - g.in_mk_themerooms = TRUE; + iflags.in_lua = g.in_mk_themerooms = TRUE; g.themeroom_failed = FALSE; lua_getglobal(themes, "themerooms_generate"); lua_call(themes, 0, 0); - g.in_mk_themerooms = FALSE; + iflags.in_lua = g.in_mk_themerooms = FALSE; if (g.themeroom_failed && ((themeroom_tries++ > 10) || (g.nroom >= (MAXNROFROOMS / 6))))