puzzles: fix a minor bug in the configuration screen
- when an invalid string setting was entered, the string value would continue to be used after being freed Change-Id: I3a9da016f6f32eac8636b9f55e4e09006bc6059e
This commit is contained in:
parent
1464cb942b
commit
dbee727664
1 changed files with 16 additions and 4 deletions
|
@ -682,7 +682,8 @@ static int list_choose(const char *list_str, const char *title)
|
|||
}
|
||||
}
|
||||
|
||||
static void do_configure_item(config_item *cfg)
|
||||
/* return value is only meaningful when type == C_STRING */
|
||||
static bool do_configure_item(config_item *cfg)
|
||||
{
|
||||
switch(cfg->type)
|
||||
{
|
||||
|
@ -696,11 +697,11 @@ static void do_configure_item(config_item *cfg)
|
|||
if(rb->kbd_input(newstr, MAX_STRLEN) < 0)
|
||||
{
|
||||
sfree(newstr);
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
sfree(cfg->sval);
|
||||
cfg->sval = newstr;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
case C_BOOLEAN:
|
||||
{
|
||||
|
@ -724,6 +725,7 @@ static void do_configure_item(config_item *cfg)
|
|||
fatal("bad type");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *config_formatter(int sel, void *data, char *buf, size_t len)
|
||||
|
@ -779,12 +781,22 @@ static void config_menu(void)
|
|||
config_item old;
|
||||
int pos = rb->gui_synclist_get_sel_pos(&list);
|
||||
memcpy(&old, config + pos, sizeof(old));
|
||||
do_configure_item(config + pos);
|
||||
char *old_str;
|
||||
if(old.type == C_STRING)
|
||||
old_str = dupstr(old.sval);
|
||||
bool freed_str = do_configure_item(config + pos);
|
||||
char *err = midend_set_config(me, CFG_SETTINGS, config);
|
||||
if(err)
|
||||
{
|
||||
rb->splash(HZ, err);
|
||||
memcpy(config + pos, &old, sizeof(old));
|
||||
if(freed_str)
|
||||
config[pos].sval = old_str;
|
||||
}
|
||||
else if(old.type == C_STRING)
|
||||
{
|
||||
/* success, and we duplicated the old string, so free it */
|
||||
sfree(old_str);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue