Further changes to ensure that copy-keymap doesn't segfault

* src/keymap.c (copy_keymap_1, copy_keymap_set_char_table): Ensure
we don't recurse infinitely when using non-sparse keymaps, too.

This change makes this form not segfault:

(let ((map (make-keymap)))
  (define-key map " " map)
  (copy-keymap map))
This commit is contained in:
Lars Ingebrigtsen 2019-10-14 02:52:25 +02:00
parent ea7610f1f1
commit d1963b312d

View file

@ -975,10 +975,12 @@ copy_keymap_item (Lisp_Object elt, int depth)
}
static void
copy_keymap_set_char_table (Lisp_Object chartable, Lisp_Object idx,
copy_keymap_set_char_table (Lisp_Object chartable_and_depth, Lisp_Object idx,
Lisp_Object elt)
{
Fset_char_table_range (chartable, idx, copy_keymap_item (elt, 0));
Fset_char_table_range
(XCAR (chartable_and_depth), idx,
copy_keymap_item (elt, XFIXNUM (XCDR (chartable_and_depth))));
}
static Lisp_Object
@ -999,7 +1001,8 @@ copy_keymap_1 (Lisp_Object keymap, int depth)
if (CHAR_TABLE_P (elt))
{
elt = Fcopy_sequence (elt);
map_char_table (copy_keymap_set_char_table, Qnil, elt, elt);
map_char_table (copy_keymap_set_char_table, Qnil, elt,
Fcons (elt, make_fixnum (depth + 1)));
}
else if (VECTORP (elt))
{