1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

Merge pull request #994 from ailin-nemui/fix-993

add more config checks and assertions in statusbar code
This commit is contained in:
ailin-nemui 2019-02-02 14:34:59 +01:00 committed by GitHub
commit ff18e79661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 15 deletions

View File

@ -161,6 +161,7 @@ static void textui_init(void)
static void textui_finish_init(void) static void textui_finish_init(void)
{ {
int loglev;
quitting = FALSE; quitting = FALSE;
term_refresh_freeze(); term_refresh_freeze();
@ -176,7 +177,10 @@ static void textui_finish_init(void)
mainwindow_activity_init(); mainwindow_activity_init();
mainwindows_layout_init(); mainwindows_layout_init();
gui_windows_init(); gui_windows_init();
/* Temporarily raise the fatal level to abort on config errors. */
loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL);
statusbar_init(); statusbar_init();
g_log_set_always_fatal(loglev);
term_refresh_thaw(); term_refresh_thaw();
settings_check(); settings_check();
@ -319,6 +323,7 @@ int main(int argc, char **argv)
you have to call setlocale(LC_ALL, "") */ you have to call setlocale(LC_ALL, "") */
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
/* Temporarily raise the fatal level to abort on config errors. */
loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL); loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL);
textui_init(); textui_init();

View File

@ -150,6 +150,9 @@ static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
GSList *tmp; GSList *tmp;
const char *visible_str; const char *visible_str;
g_return_if_fail(is_node_list(node));
g_return_if_fail(node->key != NULL);
bar = statusbar_config_find(group, node->key); bar = statusbar_config_find(group, node->key);
if (config_node_get_bool(node, "disabled", FALSE)) { if (config_node_get_bool(node, "disabled", FALSE)) {
/* disabled, destroy it if it already exists */ /* disabled, destroy it if it already exists */
@ -191,10 +194,26 @@ static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
} }
} }
#define skip_corrupt_config(parent, node, index, format, ...) \
if ((node)->type != NODE_TYPE_BLOCK) { \
if ((node)->key == NULL) { \
g_critical("Expected %s node at `.." format "/%s[%d]' was of %s type. Corrupt config?", \
"block", ##__VA_ARGS__, (parent)->key, (index), \
(node)->type == NODE_TYPE_LIST ? "list" : "scalar"); \
} else { \
g_critical("Expected %s node at `.." format "/%s/%s' was of %s type. Corrupt config?", \
"block", ##__VA_ARGS__, (parent)->key, (node)->key, \
(node)->type == NODE_TYPE_LIST ? "list" : "scalar"); \
} \
continue; \
} \
static void statusbar_read_group(CONFIG_NODE *node) static void statusbar_read_group(CONFIG_NODE *node)
{ {
STATUSBAR_GROUP_REC *group; STATUSBAR_GROUP_REC *group;
GSList *tmp; GSList *tmp;
int i;
g_return_if_fail(is_node_list(node)); g_return_if_fail(is_node_list(node));
@ -205,9 +224,11 @@ static void statusbar_read_group(CONFIG_NODE *node)
active_statusbar_group = group; active_statusbar_group = group;
} }
tmp = config_node_first(node->value); for (tmp = config_node_first(node->value), i = 0; tmp != NULL; tmp = config_node_next(tmp), i++) {
for (; tmp != NULL; tmp = config_node_next(tmp)) CONFIG_NODE *value = tmp->data;
statusbar_read(group, tmp->data); skip_corrupt_config(node, value, i, "statusbar");
statusbar_read(group, value);
}
} }
static void create_root_statusbars(void) static void create_root_statusbars(void)
@ -228,17 +249,20 @@ static void create_root_statusbars(void)
static void read_statusbar_config_from_node(CONFIG_NODE *node) static void read_statusbar_config_from_node(CONFIG_NODE *node)
{ {
CONFIG_NODE *items; CONFIG_NODE *items, *group;
GSList *tmp; GSList *tmp;
int i;
items = iconfig_node_section(node, "items", -1); items = iconfig_node_section(node, "items", -1);
if (items != NULL) if (items != NULL)
statusbar_read_items(items); statusbar_read_items(items);
tmp = config_node_first(node->value); for (tmp = config_node_first(node->value), i = 0; tmp != NULL; tmp = config_node_next(tmp), i++) {
for (; tmp != NULL; tmp = config_node_next(tmp)) { group = tmp->data;
if (tmp->data != items) if (group != items) {
statusbar_read_group(tmp->data); skip_corrupt_config(node, group, i, "");
statusbar_read_group(group);
}
} }
} }

View File

@ -62,20 +62,21 @@ CONFIG_NODE *config_node_section_index(CONFIG_REC *rec, CONFIG_NODE *parent, con
parent->value = g_slist_insert(parent->value, node, index); parent->value = g_slist_insert(parent->value, node, index);
} }
if (!is_node_list(node)) { if (!is_node_list(node)) {
int show_error = 0; int error = 0;
if (new_type != -1) { if (new_type != -1) {
config_node_remove(rec, parent, node); config_node_remove(rec, parent, node);
node = NULL; node = NULL;
show_error = 1; error = 1;
} else if (!g_hash_table_lookup_extended(rec->cache_nodes, node, NULL, NULL)) { } else if (!g_hash_table_lookup_extended(rec->cache_nodes, node, NULL, NULL)) {
g_hash_table_insert(rec->cache_nodes, node, NULL); g_hash_table_insert(rec->cache_nodes, node, NULL);
show_error = 1; error = 1;
} }
if (show_error) if (error)
g_critical("Expected %s node at `..%s/%s' was of scalar type. Corrupt config?", g_critical("Expected %s node at `%s%s/%s' was of scalar type. Corrupt config?",
new_type == NODE_TYPE_LIST ? "list" : new_type == NODE_TYPE_BLOCK ? "block" : "section", new_type == NODE_TYPE_LIST ? "list" : new_type == NODE_TYPE_BLOCK ? "block" : "section",
parent->key, key); parent == rec->mainnode ? "" : "..",
parent->key == NULL ? "" : parent->key, key);
} else { } else {
g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL); g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL);
return node; return node;