Subject: Re: bug#61647: edit-kbd-macro: Wrong type argument: characterp, 134217785

From: Daniel Martín <[email-masked]>
Date: Mon, 20 Feb 2023 12:39:25 +0100

Eduardo Ochs <[email-masked]> writes:

> Hi all, I found a keyboard macro on which edit-kbd-macro fails with
> this error:
>
>   edit-kbd-macro: Wrong type argument: characterp, 134217785
>
> To reproduce the error run any of these two setqs - they should be
> equivalent -
>
>   (setq last-kbd-macro [134217847 134217785 134217785 134217834 5 32
>     25 1 67108896 down 134217847 134217777 134217834 return 25
>     134217803 134217803])
>
>   (setq last-kbd-macro (kbd "M-w M-99 M-j C-e SPC C-y C-a C-SPC <down>
>     M-w M-1 M-j RET C-y 2*M-K"))
>
> and then run `M-x edit-kbd-macro C-x e'.
>

This is the commit that introduced this regression:

commit e5695faec4a43f10be3b56fa7fd436d5f54a5761
Author: Mattias Engdegård <[email-masked]>
Date:   Fri Aug 19 13:27:53 2022 +0200

    * lisp/edmacro.el (edmacro-sanitize-for-string): Fix condition.
    
    This is of little consequence in practice since the input is always a
    vector of keys representing a prefix, where bit 7 isn't likely to be
    set when higher bits are set, but it silences a (justified) warning.

diff --git a/lisp/edmacro.el b/lisp/edmacro.el
index efffab9b30b..26a5d2347f0 100644
--- a/lisp/edmacro.el
+++ b/lisp/edmacro.el
@@ -626,7 +626,7 @@ edmacro-sanitize-for-string
 This function assumes that the events can be stored in a string."
   (setq seq (copy-sequence seq))
   (cl-loop for i below (length seq) do
-           (when (logand (aref seq i) 128)
+           (when (/= (logand (aref seq i) 128) 0)
              (setf (aref seq i) (logand (aref seq i) 127))))
   seq)
 
Adding Mattias to the CC.