]> granicus.if.org Git - nethack/commitdiff
fix segfault with #therecmdmenu
authorPatR <rankin@nethack.org>
Mon, 16 May 2022 16:41:21 +0000 (09:41 -0700)
committerPatR <rankin@nethack.org>
Mon, 16 May 2022 16:41:21 +0000 (09:41 -0700)
The change to add a menu choice for naming an adjacent monster via
\#therecmdmenu was unintentionally requiring that the monster have
monst->mextra.  So it worked on pets (regardless of whether they
were already named) because they have mextra for 'edog' extension,
but not on the majority of monsters.  And when it failed the program
would crash with a 'segmentation fault' error.

Fix the check for whether a target monster already had a name when
deciding to use "name <mon>" or "rename <mon>" in the menu entry.

doc/fixes3-7-0.txt
src/cmd.c

index dbe8ff0bbf015070407cbcb6d1621cb84f6c86b1..e36cae2705a46db95f23b69ac0ffb1e0ac879cff 100644 (file)
@@ -1,4 +1,4 @@
-HDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.916 $ $NHDT-Date: 1652689792 2022/05/16 08:29:52 $
+HDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.917 $ $NHDT-Date: 1652719274 2022/05/16 16:41:14 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -1215,6 +1215,8 @@ recent changes in removing a dead monster from the map didn't update screen
        to show objects it dropped; they were present, just not displayed
 further changes resulted in dead monsters' corpses be placed at <0,0>;
        reverse the part(s) that cleared stale monst->mx,my
+adding name/rename choice to #therecmdmenu caused it to crash when picking an
+       adjacent unnamed, untame monster
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index b4e76919b643bba92cbcd19df3b6b7075ea6dcea..99804960c762d5f46d032ca94d60127098c1775e 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 cmd.c   $NHDT-Date: 1652637694 2022/05/15 18:01:34 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.563 $ */
+/* NetHack 3.7 cmd.c   $NHDT-Date: 1652719274 2022/05/16 16:41:14 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.564 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2013. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -4764,7 +4764,7 @@ there_cmd_menu_next2u(
     }
     if (mtmp) {
         Sprintf(buf, "%s %s",
-                !MGIVENNAME(mtmp) ? "Name" : "Rename",
+                !has_mgivenname(mtmp) ? "Name" : "Rename",
                 mon_nam(mtmp));
         mcmd_addmenu(win, MCMD_NAME, buf), ++K;
     }