core: fix NULL pointer in free of bar window (closes #293); add extra checks on bar window pointers

This commit is contained in:
Sébastien Helleu 2015-01-03 19:18:09 +01:00
parent 6d1251415f
commit ca5aa6695f
2 changed files with 27 additions and 4 deletions

View File

@ -686,9 +686,12 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
int max_length, max_length_screen;
int total_items, columns, lines;
if (!bar_window->items_subcount || !bar_window->items_content
if (!bar_window
|| !bar_window->items_subcount || !bar_window->items_content
|| !bar_window->items_num_lines || !bar_window->items_refresh_needed)
{
return NULL;
}
snprintf (str_reinit_color, sizeof (str_reinit_color),
"%c",
@ -993,6 +996,9 @@ gui_bar_window_coords_add (struct t_gui_bar_window *bar_window,
{
struct t_gui_bar_window_coords **coords2;
if (!bar_window)
return;
if (!bar_window->coords)
{
bar_window->coords_count = 1;
@ -1032,6 +1038,9 @@ gui_bar_window_coords_free (struct t_gui_bar_window *bar_window)
{
int i;
if (!bar_window)
return;
if (bar_window->coords)
{
for (i = 0; i < bar_window->coords_count; i++)
@ -1055,6 +1064,9 @@ gui_bar_window_insert (struct t_gui_bar_window *bar_window,
{
struct t_gui_bar_window *pos_bar_window;
if (!bar_window || !window)
return;
if (window->bar_windows)
{
pos_bar_window = gui_bar_window_find_pos (bar_window->bar, window);
@ -1164,7 +1176,7 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
int
gui_bar_window_get_current_size (struct t_gui_bar_window *bar_window)
{
return bar_window->current_size;
return (bar_window) ? bar_window->current_size : 0;
}
/*
@ -1243,6 +1255,9 @@ gui_bar_window_set_current_size (struct t_gui_bar_window *bar_window,
{
int new_size, max_size;
if (!bar_window)
return;
if (size == 0)
new_size = 1;
else
@ -1285,6 +1300,9 @@ void
gui_bar_window_free (struct t_gui_bar_window *bar_window,
struct t_gui_window *window)
{
if (!bar_window)
return;
/* remove window bar from list */
if (window)
{
@ -1437,6 +1455,9 @@ gui_bar_window_scroll (struct t_gui_bar_window *bar_window,
{
int old_scroll_x, old_scroll_y;
if (!bar_window)
return;
old_scroll_x = bar_window->scroll_x;
old_scroll_y = bar_window->scroll_y;

View File

@ -863,11 +863,13 @@ gui_bar_config_change_hidden (void *data, struct t_config_option *option)
{
if (CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]))
{
gui_bar_window_free (ptr_bar->bar_window, NULL);
if (ptr_bar->bar_window)
gui_bar_window_free (ptr_bar->bar_window, NULL);
}
else
{
gui_bar_window_new (ptr_bar, NULL);
if (!ptr_bar->bar_window)
gui_bar_window_new (ptr_bar, NULL);
}
}
else