mirror of
https://github.com/irssi/irssi.git
synced 2024-10-27 05:20:20 -04:00
Merge pull request #994 from ailin-nemui/fix-993
add more config checks and assertions in statusbar code
This commit is contained in:
commit
ff18e79661
@ -161,6 +161,7 @@ static void textui_init(void)
|
||||
|
||||
static void textui_finish_init(void)
|
||||
{
|
||||
int loglev;
|
||||
quitting = FALSE;
|
||||
|
||||
term_refresh_freeze();
|
||||
@ -176,7 +177,10 @@ static void textui_finish_init(void)
|
||||
mainwindow_activity_init();
|
||||
mainwindows_layout_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();
|
||||
g_log_set_always_fatal(loglev);
|
||||
term_refresh_thaw();
|
||||
|
||||
settings_check();
|
||||
@ -319,6 +323,7 @@ int main(int argc, char **argv)
|
||||
you have to call 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);
|
||||
textui_init();
|
||||
|
||||
|
@ -150,6 +150,9 @@ static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
|
||||
GSList *tmp;
|
||||
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);
|
||||
if (config_node_get_bool(node, "disabled", FALSE)) {
|
||||
/* 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)
|
||||
{
|
||||
STATUSBAR_GROUP_REC *group;
|
||||
GSList *tmp;
|
||||
int i;
|
||||
|
||||
g_return_if_fail(is_node_list(node));
|
||||
|
||||
@ -205,9 +224,11 @@ static void statusbar_read_group(CONFIG_NODE *node)
|
||||
active_statusbar_group = group;
|
||||
}
|
||||
|
||||
tmp = config_node_first(node->value);
|
||||
for (; tmp != NULL; tmp = config_node_next(tmp))
|
||||
statusbar_read(group, tmp->data);
|
||||
for (tmp = config_node_first(node->value), i = 0; tmp != NULL; tmp = config_node_next(tmp), i++) {
|
||||
CONFIG_NODE *value = tmp->data;
|
||||
skip_corrupt_config(node, value, i, "statusbar");
|
||||
statusbar_read(group, value);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CONFIG_NODE *items;
|
||||
CONFIG_NODE *items, *group;
|
||||
GSList *tmp;
|
||||
int i;
|
||||
|
||||
items = iconfig_node_section(node, "items", -1);
|
||||
if (items != NULL)
|
||||
statusbar_read_items(items);
|
||||
|
||||
tmp = config_node_first(node->value);
|
||||
for (; tmp != NULL; tmp = config_node_next(tmp)) {
|
||||
if (tmp->data != items)
|
||||
statusbar_read_group(tmp->data);
|
||||
for (tmp = config_node_first(node->value), i = 0; tmp != NULL; tmp = config_node_next(tmp), i++) {
|
||||
group = tmp->data;
|
||||
if (group != items) {
|
||||
skip_corrupt_config(node, group, i, "");
|
||||
statusbar_read_group(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
if (!is_node_list(node)) {
|
||||
int show_error = 0;
|
||||
int error = 0;
|
||||
|
||||
if (new_type != -1) {
|
||||
config_node_remove(rec, parent, node);
|
||||
node = NULL;
|
||||
show_error = 1;
|
||||
error = 1;
|
||||
} else if (!g_hash_table_lookup_extended(rec->cache_nodes, node, NULL, NULL)) {
|
||||
g_hash_table_insert(rec->cache_nodes, node, NULL);
|
||||
show_error = 1;
|
||||
error = 1;
|
||||
}
|
||||
if (show_error)
|
||||
g_critical("Expected %s node at `..%s/%s' was of scalar type. Corrupt config?",
|
||||
new_type == NODE_TYPE_LIST ? "list" : new_type == NODE_TYPE_BLOCK ? "block" : "section",
|
||||
parent->key, key);
|
||||
if (error)
|
||||
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",
|
||||
parent == rec->mainnode ? "" : "..",
|
||||
parent->key == NULL ? "" : parent->key, key);
|
||||
} else {
|
||||
g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL);
|
||||
return node;
|
||||
|
Loading…
Reference in New Issue
Block a user