Subject: bug#62867: segfault in describe_vector

From: Stefan Monnier <[email-masked]>
Date: Sat, 15 Apr 2023 18:16:32 -0400

> Stefan, can we do better than the below?

The patch looks about right to me.

Only detail is that `shadowed_by` contains a binding, so it can be
a keymap, but it can also be a lambda expression, or a keyboard macro,
so we shouldn't say "shadowed by a keymap" but just "shadowed" (unless
we go through the extra trouble of checking if it's a keymap, or if it's
a ...).

        Stefan

> 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);
>  	}
>      }