Skip to content

Commit

Permalink
49377: fix segfault by 'bindkey -d' with reordered keymapnamtab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun-T committed Sep 8, 2021
1 parent bb61da3 commit 2a7945a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-09-08 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>

* 49377: Src/Zle/zle_keymap.c, Test/X03zlebindkey.ztst: fix
segfalut by 'bindkey -d' with reordered keymapnamtab

2021-09-06 Bart Schaefer <schaefer@zsh.org>

* Stephane Chazelas: 45180: Doc/Zsh/contrib.yo,
Expand Down
22 changes: 21 additions & 1 deletion Src/Zle/zle_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ createkeymapnamtab(void)
keymapnamtab = newhashtable(7, "keymapnamtab", NULL);

keymapnamtab->hash = hasher;
keymapnamtab->emptytable = emptyhashtable;
keymapnamtab->emptytable = emptykeymapnamtab;
keymapnamtab->filltable = NULL;
keymapnamtab->cmpnodes = strcmp;
keymapnamtab->addnode = addhashnode;
Expand All @@ -178,6 +178,26 @@ makekeymapnamnode(Keymap keymap)
return kmn;
}

/**/
static void
emptykeymapnamtab(HashTable ht)
{
struct hashnode *hn, *hp;
int i;

for (i = 0; i < ht->hsize; i++) {
for (hn = ht->nodes[i]; hn;) {
KeymapName kmn = (KeymapName) hn;
hp = hn->next;
zsfree(kmn->nam);
unrefkeymap(kmn->keymap);
zfree(kmn, sizeof(*kmn));
hn = hp;
}
ht->nodes[i] = NULL;
}
ht->ct = 0;
}

/*
* Reference a keymap from a keymapname.
Expand Down
15 changes: 15 additions & 0 deletions Test/X03zlebindkey.ztst
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,18 @@
>CURSOR: 18
>BUFFER: echo $(( ##x ) ##x ) y
>CURSOR: 22

bindkey -d
for name in a b c d e; bindkey -N $name
bindkey -d
bindkey -l
0:delete all keymaps after expanding keymapnamtab
>.safe
>command
>emacs
>isearch
>main
>vicmd
>viins
>viopp
>visual

0 comments on commit 2a7945a

Please sign in to comment.