mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Use a malloc'd buffer for lsk since commands can be very long, from Gregory Pakosz.
This commit is contained in:
parent
f4c7141f5d
commit
02253d1e5c
@ -61,8 +61,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct key_table *table;
|
struct key_table *table;
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *tablename, *r;
|
const char *tablename, *r;
|
||||||
char *key, *cp, tmp[8192];
|
char *key, *cp, *tmp;
|
||||||
int repeat, width, tablewidth, keywidth;
|
int repeat, width, tablewidth, keywidth;
|
||||||
|
size_t tmpsize, tmpused, cplen;
|
||||||
|
|
||||||
if (self->entry == &cmd_list_commands_entry)
|
if (self->entry == &cmd_list_commands_entry)
|
||||||
return (cmd_list_keys_commands(self, item));
|
return (cmd_list_keys_commands(self, item));
|
||||||
@ -101,6 +102,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
table = key_bindings_next_table(table);
|
table = key_bindings_next_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpsize = 256;
|
||||||
|
tmp = xmalloc(tmpsize);
|
||||||
|
|
||||||
table = key_bindings_first_table ();
|
table = key_bindings_first_table ();
|
||||||
while (table != NULL) {
|
while (table != NULL) {
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||||
@ -117,20 +121,35 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
r = "-r ";
|
r = "-r ";
|
||||||
else
|
else
|
||||||
r = " ";
|
r = " ";
|
||||||
xsnprintf(tmp, sizeof tmp, "%s-T ", r);
|
tmpused = xsnprintf(tmp, tmpsize, "%s-T ", r);
|
||||||
|
|
||||||
cp = utf8_padcstr(table->name, tablewidth);
|
cp = utf8_padcstr(table->name, tablewidth);
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
cplen = strlen(cp) + 1;
|
||||||
strlcat(tmp, " ", sizeof tmp);
|
while (tmpused + cplen + 1>= tmpsize) {
|
||||||
|
tmpsize *= 2;
|
||||||
|
tmp = xrealloc(tmp, tmpsize);
|
||||||
|
}
|
||||||
|
tmpused = strlcat(tmp, cp, tmpsize);
|
||||||
|
tmpused = strlcat(tmp, " ", tmpsize);
|
||||||
free(cp);
|
free(cp);
|
||||||
|
|
||||||
cp = utf8_padcstr(key, keywidth);
|
cp = utf8_padcstr(key, keywidth);
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
cplen = strlen(cp) + 1;
|
||||||
strlcat(tmp, " ", sizeof tmp);
|
while (tmpused + cplen + 1 >= tmpsize) {
|
||||||
|
tmpsize *= 2;
|
||||||
|
tmp = xrealloc(tmp, tmpsize);
|
||||||
|
}
|
||||||
|
tmpused = strlcat(tmp, cp, tmpsize);
|
||||||
|
tmpused = strlcat(tmp, " ", tmpsize);
|
||||||
free(cp);
|
free(cp);
|
||||||
|
|
||||||
cp = cmd_list_print(bd->cmdlist, 1);
|
cp = cmd_list_print(bd->cmdlist, 1);
|
||||||
strlcat(tmp, cp, sizeof tmp);
|
cplen = strlen(cp);
|
||||||
|
while (tmpused + cplen + 1 >= tmpsize) {
|
||||||
|
tmpsize *= 2;
|
||||||
|
tmp = xrealloc(tmp, tmpsize);
|
||||||
|
}
|
||||||
|
strlcat(tmp, cp, tmpsize);
|
||||||
free(cp);
|
free(cp);
|
||||||
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
cmdq_print(item, "bind-key %s", tmp);
|
||||||
@ -141,6 +160,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
table = key_bindings_next_table(table);
|
table = key_bindings_next_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user