]> granicus.if.org Git - nethack/commitdiff
fix a segfault in mapglyph reported by Pasi earlier today
authornhmall <mjnh@persona.ca>
Tue, 10 Mar 2015 01:08:26 +0000 (21:08 -0400)
committerPasi Kallinen <paxed@alt.org>
Tue, 17 Mar 2015 16:47:19 +0000 (18:47 +0200)
 Changes to be committed:
modified:   src/pager.c

Steps to reproduce the reported segfault:
Use / command, answer n, press space and enter

In do_look() variable glyph is only set to a proper
value if using the screen (from_screen) or the
mouse (clicklook).

On the code path that triggered the segfault,
glyph was being passed to mapglyph with a random
arbitrary value.

If glyph had been initialized at the start of
do_look(), it would have prevented the segfault,
but would have always displayed a giant ant or
something silly instead of the correct thing.

Don't use glyph except under
from_screen || clicklook.

src/pager.c

index 4e8008c1be7860b41e213331960b988e54b66c74..72111906075233af3ad2653a0d48da258a824cc0 100644 (file)
@@ -574,9 +574,14 @@ do_look(mode, click_cc)
                def_monsyms[i].explain) {
                need_to_look = TRUE;
                if (!found) {
-                   Sprintf(out_str, "%s        %s",
+                   if (from_screen || clicklook)
+                       Sprintf(out_str, "%s        %s",
                                encglyph(glyph),
-                               an(def_monsyms[i].explain));
+                               an(def_monsyms[i].explain));
+                   else
+                       Sprintf(out_str, "%c        %s",
+                               sym,
+                               an(def_monsyms[i].explain));
                    firstmatch = def_monsyms[i].explain;
                    found++;
                } else {