Do not crash when calling choose-tree with a command that changes the mode.

This commit is contained in:
Nicholas Marriott 2013-02-13 11:01:26 +00:00
parent f4c815a1d9
commit 362c460767
2 changed files with 15 additions and 11 deletions

2
cmd.c
View File

@ -1228,7 +1228,7 @@ cmd_template_replace(const char *template, const char *s, int idx)
int replaced;
size_t len;
if (strstr(template, "%") == NULL)
if (strchr(template, '%') == NULL)
return (xstrdup(template));
buf = xmalloc(1);

View File

@ -77,6 +77,7 @@ struct window_choose_mode_data {
void (*callbackfn)(struct window_choose_data *);
};
void window_choose_free1(struct window_choose_mode_data *);
int window_choose_key_index(struct window_choose_mode_data *, u_int);
int window_choose_index_key(struct window_choose_mode_data *, int);
void window_choose_prompt_input(enum window_choose_input_type,
@ -246,10 +247,19 @@ window_choose_default_callback(struct window_choose_data *wcd)
void
window_choose_free(struct window_pane *wp)
{
struct window_choose_mode_data *data = wp->modedata;
if (wp->modedata != NULL)
window_choose_free1(wp->modedata);
}
void
window_choose_free1(struct window_choose_mode_data *data)
{
struct window_choose_mode_item *item;
u_int i;
if (data == NULL)
return;
for (i = 0; i < ARRAY_LENGTH(&data->old_list); i++) {
item = &ARRAY_ITEM(&data->old_list, i);
window_choose_data_free(item->wcd);
@ -282,14 +292,13 @@ window_choose_fire_callback(
struct window_pane *wp, struct window_choose_data *wcd)
{
struct window_choose_mode_data *data = wp->modedata;
const struct window_mode *oldmode;
oldmode = wp->mode;
wp->mode = NULL;
wp->modedata = NULL;
window_pane_reset_mode(wp);
data->callbackfn(wcd);
wp->mode = oldmode;
window_choose_free1(data);
}
void
@ -500,7 +509,6 @@ window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
}
item = &ARRAY_ITEM(&data->list, n);
window_choose_fire_callback(wp, item->wcd);
window_pane_reset_mode(wp);
break;
case MODEKEYCHOICE_BACKSPACE:
input_len = strlen(data->input_str);
@ -521,12 +529,10 @@ window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
switch (mode_key_lookup(&data->mdata, key)) {
case MODEKEYCHOICE_CANCEL:
window_choose_fire_callback(wp, NULL);
window_pane_reset_mode(wp);
break;
case MODEKEYCHOICE_CHOOSE:
item = &ARRAY_ITEM(&data->list, data->selected);
window_choose_fire_callback(wp, item->wcd);
window_pane_reset_mode(wp);
break;
case MODEKEYCHOICE_TREE_TOGGLE:
item = &ARRAY_ITEM(&data->list, data->selected);
@ -676,7 +682,6 @@ window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
item = &ARRAY_ITEM(&data->list, data->selected);
window_choose_fire_callback(wp, item->wcd);
window_pane_reset_mode(wp);
break;
}
}
@ -705,7 +710,6 @@ window_choose_mouse(
item = &ARRAY_ITEM(&data->list, data->selected);
window_choose_fire_callback(wp, item->wcd);
window_pane_reset_mode(wp);
}
void