]> granicus.if.org Git - nethack/commitdiff
fix pull request #471 - error message segfault
authorPatR <rankin@nethack.org>
Wed, 17 Mar 2021 01:45:56 +0000 (18:45 -0700)
committerPatR <rankin@nethack.org>
Wed, 17 Mar 2021 01:45:56 +0000 (18:45 -0700)
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

doc/fixes37.0
src/files.c
src/mklev.c

index c0271d18bb8d5d257777b6e3db0313bb61aa7e12..1dfbf18c279a6326358079149c006e9f6e58a0ab 100644 (file)
@@ -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
index c488ae93c2fed8afadb309777fa39854bdd45f43..58ede76f858d484aca0acc96740c49d8232daddc 100644 (file)
@@ -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;
index dde1b8165f843eaecbdc92cc1b624f82acacf12b..dc606f7adacfaadd2cfafcb298e5dd3b8791d9cd 100644 (file)
@@ -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))))