Subject: Re: bug#62867: segfault in describe_vector

From: Eli Zaretskii <[email-masked]>
Date: Sat, 15 Apr 2023 22:33:03 +0300

> From: Xinyang Chen <[email-masked]>
> Date: Sat, 15 Apr 2023 08:07:07 -0400
> 
> to reproduce:
> 
> (package-initialize)
> (require 'evil)
> (setq testmap (make-sparse-keymap))
> (define-key testmap (kbd "SPC") #'test)
> (evil-define-key 'motion global-map (kbd "SPC") testmap)
> (evil-mode)
> (describe-keymap global-map)
> 
> This appears to be caused by keymap.c line 3313
> SYMBOL_NAME (shadowed_by)
> where shadowed_by don't have to be a symbol (In this case its a keymap)

No good deed goes unpunished...

Stefan, can we do better than the below?

diff --git a/src/keymap.c b/src/keymap.c
index efac410..b9950b9 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -3308,13 +3308,18 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args,
       if (this_shadowed)
 	{
 	  SET_PT (PT - 1);
-	  static char const fmt[] = "  (currently shadowed by `%s')";
-	  USE_SAFE_ALLOCA;
-	  char *buffer = SAFE_ALLOCA (sizeof fmt +
-				      SBYTES (SYMBOL_NAME (shadowed_by)));
-	  esprintf (buffer, fmt, SDATA (SYMBOL_NAME (shadowed_by)));
-	  insert_string (buffer);
-	  SAFE_FREE();
+	  if (SYMBOLP (shadowed_by))
+	    {
+	      static char const fmt[] = "  (currently shadowed by `%s')";
+	      USE_SAFE_ALLOCA;
+	      char *buffer =
+		SAFE_ALLOCA (sizeof fmt + SBYTES (SYMBOL_NAME (shadowed_by)));
+	      esprintf (buffer, fmt, SDATA (SYMBOL_NAME (shadowed_by)));
+	      insert_string (buffer);
+	      SAFE_FREE();
+	    }
+	  else
+	    insert_string ("  (binding currently shadowed by a keymap)");
 	  SET_PT (PT + 1);
 	}
     }