diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-05 14:45:26 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-02-05 14:45:26 +0100 |
commit | d7bec49b713608d0b1caeb8e5f2fee790de2f14c (patch) | |
tree | 0e568826d251dab9eae0991e2f11521a94ae24ac | |
parent | a26e57eebefbc50d528695ddc9db9ff828691dae (diff) | |
download | weechat-d7bec49b713608d0b1caeb8e5f2fee790de2f14c.zip |
Fix crash with nicklist bar when position is top/bottom and filling is columns
-rw-r--r-- | src/gui/gui-bar-window.c | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/src/gui/gui-bar-window.c b/src/gui/gui-bar-window.c index 7bc6bf413..96cc1c402 100644 --- a/src/gui/gui-bar-window.c +++ b/src/gui/gui-bar-window.c @@ -465,6 +465,7 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window, break; case GUI_BAR_FILLING_COLUMNS_HORIZONTAL: /* items in columns, with horizontal filling */ case GUI_BAR_FILLING_COLUMNS_VERTICAL: /* items in columns, with vertical filling */ + content = NULL; total_items = 0; max_length = 1; max_length_screen = 1; @@ -521,68 +522,77 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window, } /* build array with pointers to splitted items */ + linear_items = malloc (total_items * sizeof (*linear_items)); - index = 0; - for (i = 0; i < bar_window->items_count; i++) + if (linear_items) { - if (splitted_items[i]) + index = 0; + for (i = 0; i < bar_window->items_count; i++) { - for (sub = 0; sub < bar_window->items_subcount[i]; sub++) + if (splitted_items[i]) { - if (splitted_items[i][sub]) + for (sub = 0; sub < bar_window->items_subcount[i]; sub++) { - for (j = 0; splitted_items[i][sub][j]; j++) + if (splitted_items[i][sub]) { - linear_items[index++] = splitted_items[i][sub][j]; + for (j = 0; splitted_items[i][sub][j]; j++) + { + linear_items[index++] = splitted_items[i][sub][j]; + } } } } } - } - - /* build content with lines and columns */ - content = malloc (1 + (lines * - ((columns * (max_length + length_reinit_color_space)) + 1))); - content[0] = '\0'; - index_content = 0; - for (i = 0; i < lines; i++) - { - for (j = 0; j < columns; j++) + + /* build content with lines and columns */ + content = malloc (1 + (lines * + ((columns * + (max_length + max_length_screen + length_reinit_color_space)) + 1))); + if (content) { - if (filling == GUI_BAR_FILLING_COLUMNS_HORIZONTAL) - index = (i * columns) + j; - else - index = (j * lines) + i; - - if (index >= total_items) + content[0] = '\0'; + index_content = 0; + for (i = 0; i < lines; i++) { - for (k = 0; k < max_length_screen; k++) + for (j = 0; j < columns; j++) { - content[index_content++] = ' '; - } - } - else - { - strcpy (content + index_content, linear_items[index]); - index_content += strlen (linear_items[index]); - length = max_length_screen - - gui_chat_strlen_screen (linear_items[index]); - for (k = 0; k < length; k++) - { - content[index_content++] = ' '; + if (filling == GUI_BAR_FILLING_COLUMNS_HORIZONTAL) + index = (i * columns) + j; + else + index = (j * lines) + i; + + if (index >= total_items) + { + for (k = 0; k < max_length_screen; k++) + { + content[index_content++] = ' '; + } + } + else + { + strcpy (content + index_content, linear_items[index]); + index_content += strlen (linear_items[index]); + length = max_length_screen - + gui_chat_strlen_screen (linear_items[index]); + for (k = 0; k < length; k++) + { + content[index_content++] = ' '; + } + } + if (j < columns - 1) + { + strcpy (content + index_content, reinit_color_space); + index_content += length_reinit_color_space; + } } + content[index_content++] = '\n'; } - if (j < columns - 1) - { - strcpy (content + index_content, reinit_color_space); - index_content += length_reinit_color_space; - } + content[index_content] = '\0'; } - content[index_content++] = '\n'; + + free (linear_items); } - content[index_content] = '\0'; - free (linear_items); for (i = 0; i < bar_window->items_count; i++) { if (splitted_items[i]) |