The command item changes so can't keep getting the target out of it, need to use

the one from the first item. Fixes crash reported by M Kelly.
This commit is contained in:
nicm 2019-07-10 14:33:24 +00:00
parent f4d858e7a0
commit 91b6145499

View File

@ -56,9 +56,9 @@ const struct cmd_entry cmd_send_prefix_entry = {
}; };
static struct cmdq_item * static struct cmdq_item *
cmd_send_keys_inject_key(struct client *c, struct cmdq_item *item, key_code key) cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs,
struct cmdq_item *item, key_code key)
{ {
struct cmd_find_state *fs = &item->target;
struct window_mode_entry *wme; struct window_mode_entry *wme;
struct key_table *table; struct key_table *table;
struct key_binding *bd; struct key_binding *bd;
@ -82,8 +82,8 @@ cmd_send_keys_inject_key(struct client *c, struct cmdq_item *item, key_code key)
} }
static struct cmdq_item * static struct cmdq_item *
cmd_send_keys_inject_string(struct client *c, struct cmdq_item *item, cmd_send_keys_inject_string(struct client *c, struct cmd_find_state *fs,
struct args *args, int i) struct cmdq_item *item, struct args *args, int i)
{ {
const char *s = args->argv[i]; const char *s = args->argv[i];
struct utf8_data *ud, *uc; struct utf8_data *ud, *uc;
@ -97,14 +97,14 @@ cmd_send_keys_inject_string(struct client *c, struct cmdq_item *item,
n = strtol(s, &endptr, 16); n = strtol(s, &endptr, 16);
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0') if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
return (item); return (item);
return (cmd_send_keys_inject_key(c, item, KEYC_LITERAL|n)); return (cmd_send_keys_inject_key(c, fs, item, KEYC_LITERAL|n));
} }
literal = args_has(args, 'l'); literal = args_has(args, 'l');
if (!literal) { if (!literal) {
key = key_string_lookup_string(s); key = key_string_lookup_string(s);
if (key != KEYC_NONE && key != KEYC_UNKNOWN) if (key != KEYC_NONE && key != KEYC_UNKNOWN)
return (cmd_send_keys_inject_key(c, item, key)); return (cmd_send_keys_inject_key(c, fs, item, key));
literal = 1; literal = 1;
} }
if (literal) { if (literal) {
@ -112,7 +112,7 @@ cmd_send_keys_inject_string(struct client *c, struct cmdq_item *item,
for (uc = ud; uc->size != 0; uc++) { for (uc = ud; uc->size != 0; uc++) {
if (utf8_combine(uc, &wc) != UTF8_DONE) if (utf8_combine(uc, &wc) != UTF8_DONE)
continue; continue;
item = cmd_send_keys_inject_key(c, item, wc); item = cmd_send_keys_inject_key(c, fs, item, wc);
} }
free(ud); free(ud);
} }
@ -124,6 +124,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{ {
struct args *args = self->args; struct args *args = self->args;
struct client *c = cmd_find_client(item, NULL, 1); struct client *c = cmd_find_client(item, NULL, 1);
struct cmd_find_state *fs = &item->target;
struct window_pane *wp = item->target.wp; struct window_pane *wp = item->target.wp;
struct session *s = item->target.s; struct session *s = item->target.s;
struct winlink *wl = item->target.wl; struct winlink *wl = item->target.wl;
@ -176,7 +177,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
key = options_get_number(s->options, "prefix2"); key = options_get_number(s->options, "prefix2");
else else
key = options_get_number(s->options, "prefix"); key = options_get_number(s->options, "prefix");
cmd_send_keys_inject_key(c, item, key); cmd_send_keys_inject_key(c, fs, item, key);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
@ -187,7 +188,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
for (; np != 0; np--) { for (; np != 0; np--) {
for (i = 0; i < args->argc; i++) for (i = 0; i < args->argc; i++)
item = cmd_send_keys_inject_string(c, item, args, i); item = cmd_send_keys_inject_string(c, fs, item, args, i);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);