diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2016-02-28 14:07:33 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2016-02-28 14:07:33 +0100 |
commit | 14e5fc60926fc82d7742357019bf9f445de93a82 (patch) | |
tree | 59ad1bc237e9770e96c168c294492e6dc3a57b29 | |
parent | 8ffb4ab6a2244c664a1cd7afd9c9cea81f3d9832 (diff) | |
download | weechat-14e5fc60926fc82d7742357019bf9f445de93a82.zip |
core: check that pointers received in arguments are not NULL in buffers and windows functions
-rw-r--r-- | ChangeLog.asciidoc | 2 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 399 | ||||
-rw-r--r-- | src/gui/gui-window.c | 297 |
3 files changed, 423 insertions, 275 deletions
diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index 5d1636c2e..c0d1553a4 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -32,6 +32,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] [[1.5_bugs]] === Bugs fixed +* core: check that pointers received in arguments are not NULL in buffers and + windows functions * core: fix truncation of buffer names in hotlist (issue #668) * core: fix update of window title under tmux (issue #685) * core: fix detection of python shared libraries (issue #676) diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index d62c5e0c6..60319c8d6 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -121,6 +121,9 @@ char *gui_buffer_properties_set[] = const char * gui_buffer_get_plugin_name (struct t_gui_buffer *buffer) { + if (!buffer) + return NULL; + if (buffer->plugin_name_for_upgrade) return buffer->plugin_name_for_upgrade; @@ -136,6 +139,9 @@ gui_buffer_get_plugin_name (struct t_gui_buffer *buffer) const char * gui_buffer_get_short_name (struct t_gui_buffer *buffer) { + if (!buffer) + return NULL; + return (buffer->short_name) ? buffer->short_name : buffer->name; } @@ -149,6 +155,9 @@ gui_buffer_build_full_name (struct t_gui_buffer *buffer) { int length; + if (!buffer) + return; + if (buffer->full_name) free (buffer->full_name); length = strlen (gui_buffer_get_plugin_name (buffer)) + 1 + @@ -231,6 +240,9 @@ gui_buffer_notify_get (struct t_gui_buffer *buffer) int length; struct t_config_option *ptr_option; + if (!buffer) + return CONFIG_INTEGER(config_look_buffer_notify_default); + length = strlen (buffer->full_name) + 1; option_name = malloc (length); if (option_name) @@ -279,6 +291,9 @@ gui_buffer_notify_set (struct t_gui_buffer *buffer) { int old_notify, new_notify; + if (!buffer) + return; + old_notify = buffer->notify; new_notify = gui_buffer_notify_get (buffer); @@ -328,6 +343,9 @@ gui_buffer_find_pos (struct t_gui_buffer *buffer) { struct t_gui_buffer *ptr_buffer; + if (!buffer) + return NULL; + /* if no number is asked by layout, position is undefined */ if (buffer->layout_number < 1) return NULL; @@ -770,7 +788,7 @@ gui_buffer_string_replace_local_var (struct t_gui_buffer *buffer, char *result, *result2, *local_var; const char *pos_end_name, *ptr_value; - if (!string) + if (!buffer || !string) return NULL; length = strlen (string) + 1; @@ -854,6 +872,9 @@ gui_buffer_match_list_split (struct t_gui_buffer *buffer, int i, match; char *ptr_name; + if (!buffer) + return 0; + match = 0; for (i = 0; i < num_buffers; i++) @@ -893,7 +914,7 @@ gui_buffer_match_list (struct t_gui_buffer *buffer, const char *string) char **buffers; int num_buffers, match; - if (!string || !string[0]) + if (!buffer || !string || !string[0]) return 0; match = 0; @@ -966,85 +987,85 @@ gui_buffer_property_in_list (char *properties[], char *property) int gui_buffer_get_integer (struct t_gui_buffer *buffer, const char *property) { - if (buffer && property) - { - if (string_strcasecmp (property, "number") == 0) - return buffer->number; - else if (string_strcasecmp (property, "layout_number") == 0) - return buffer->layout_number; - else if (string_strcasecmp (property, "layout_number_merge_order") == 0) - return buffer->layout_number_merge_order; - else if (string_strcasecmp (property, "short_name_is_set") == 0) - return (buffer->short_name) ? 1 : 0; - else if (string_strcasecmp (property, "type") == 0) - return buffer->type; - else if (string_strcasecmp (property, "notify") == 0) - return buffer->notify; - else if (string_strcasecmp (property, "num_displayed") == 0) - return buffer->num_displayed; - else if (string_strcasecmp (property, "active") == 0) - return buffer->active; - else if (string_strcasecmp (property, "hidden") == 0) - return buffer->hidden; - else if (string_strcasecmp (property, "zoomed") == 0) - return buffer->zoomed; - else if (string_strcasecmp (property, "print_hooks_enabled") == 0) - return buffer->print_hooks_enabled; - else if (string_strcasecmp (property, "day_change") == 0) - return buffer->day_change; - else if (string_strcasecmp (property, "clear") == 0) - return buffer->clear; - else if (string_strcasecmp (property, "filter") == 0) - return buffer->filter; - else if (string_strcasecmp (property, "closing") == 0) - return buffer->closing; - else if (string_strcasecmp (property, "lines_hidden") == 0) - return buffer->lines->lines_hidden; - else if (string_strcasecmp (property, "prefix_max_length") == 0) - return buffer->lines->prefix_max_length; - else if (string_strcasecmp (property, "time_for_each_line") == 0) - return buffer->time_for_each_line; - else if (string_strcasecmp (property, "nicklist") == 0) - return buffer->nicklist; - else if (string_strcasecmp (property, "nicklist_case_sensitive") == 0) - return buffer->nicklist_case_sensitive; - else if (string_strcasecmp (property, "nicklist_max_length") == 0) - return buffer->nicklist_max_length; - else if (string_strcasecmp (property, "nicklist_display_groups") == 0) - return buffer->nicklist_display_groups; - else if (string_strcasecmp (property, "nicklist_count") == 0) - return buffer->nicklist_count; - else if (string_strcasecmp (property, "nicklist_groups_count") == 0) - return buffer->nicklist_groups_count; - else if (string_strcasecmp (property, "nicklist_nicks_count") == 0) - return buffer->nicklist_nicks_count; - else if (string_strcasecmp (property, "nicklist_visible_count") == 0) - return buffer->nicklist_visible_count; - else if (string_strcasecmp (property, "input") == 0) - return buffer->input; - else if (string_strcasecmp (property, "input_get_unknown_commands") == 0) - return buffer->input_get_unknown_commands; - else if (string_strcasecmp (property, "input_size") == 0) - return buffer->input_buffer_size; - else if (string_strcasecmp (property, "input_length") == 0) - return buffer->input_buffer_length; - else if (string_strcasecmp (property, "input_pos") == 0) - return buffer->input_buffer_pos; - else if (string_strcasecmp (property, "input_1st_display") == 0) - return buffer->input_buffer_1st_display; - else if (string_strcasecmp (property, "num_history") == 0) - return buffer->num_history; - else if (string_strcasecmp (property, "text_search") == 0) - return buffer->text_search; - else if (string_strcasecmp (property, "text_search_exact") == 0) - return buffer->text_search_exact; - else if (string_strcasecmp (property, "text_search_regex") == 0) - return buffer->text_search_regex; - else if (string_strcasecmp (property, "text_search_where") == 0) - return buffer->text_search_where; - else if (string_strcasecmp (property, "text_search_found") == 0) - return buffer->text_search_found; - } + if (!buffer || !property) + return 0; + + if (string_strcasecmp (property, "number") == 0) + return buffer->number; + else if (string_strcasecmp (property, "layout_number") == 0) + return buffer->layout_number; + else if (string_strcasecmp (property, "layout_number_merge_order") == 0) + return buffer->layout_number_merge_order; + else if (string_strcasecmp (property, "short_name_is_set") == 0) + return (buffer->short_name) ? 1 : 0; + else if (string_strcasecmp (property, "type") == 0) + return buffer->type; + else if (string_strcasecmp (property, "notify") == 0) + return buffer->notify; + else if (string_strcasecmp (property, "num_displayed") == 0) + return buffer->num_displayed; + else if (string_strcasecmp (property, "active") == 0) + return buffer->active; + else if (string_strcasecmp (property, "hidden") == 0) + return buffer->hidden; + else if (string_strcasecmp (property, "zoomed") == 0) + return buffer->zoomed; + else if (string_strcasecmp (property, "print_hooks_enabled") == 0) + return buffer->print_hooks_enabled; + else if (string_strcasecmp (property, "day_change") == 0) + return buffer->day_change; + else if (string_strcasecmp (property, "clear") == 0) + return buffer->clear; + else if (string_strcasecmp (property, "filter") == 0) + return buffer->filter; + else if (string_strcasecmp (property, "closing") == 0) + return buffer->closing; + else if (string_strcasecmp (property, "lines_hidden") == 0) + return buffer->lines->lines_hidden; + else if (string_strcasecmp (property, "prefix_max_length") == 0) + return buffer->lines->prefix_max_length; + else if (string_strcasecmp (property, "time_for_each_line") == 0) + return buffer->time_for_each_line; + else if (string_strcasecmp (property, "nicklist") == 0) + return buffer->nicklist; + else if (string_strcasecmp (property, "nicklist_case_sensitive") == 0) + return buffer->nicklist_case_sensitive; + else if (string_strcasecmp (property, "nicklist_max_length") == 0) + return buffer->nicklist_max_length; + else if (string_strcasecmp (property, "nicklist_display_groups") == 0) + return buffer->nicklist_display_groups; + else if (string_strcasecmp (property, "nicklist_count") == 0) + return buffer->nicklist_count; + else if (string_strcasecmp (property, "nicklist_groups_count") == 0) + return buffer->nicklist_groups_count; + else if (string_strcasecmp (property, "nicklist_nicks_count") == 0) + return buffer->nicklist_nicks_count; + else if (string_strcasecmp (property, "nicklist_visible_count") == 0) + return buffer->nicklist_visible_count; + else if (string_strcasecmp (property, "input") == 0) + return buffer->input; + else if (string_strcasecmp (property, "input_get_unknown_commands") == 0) + return buffer->input_get_unknown_commands; + else if (string_strcasecmp (property, "input_size") == 0) + return buffer->input_buffer_size; + else if (string_strcasecmp (property, "input_length") == 0) + return buffer->input_buffer_length; + else if (string_strcasecmp (property, "input_pos") == 0) + return buffer->input_buffer_pos; + else if (string_strcasecmp (property, "input_1st_display") == 0) + return buffer->input_buffer_1st_display; + else if (string_strcasecmp (property, "num_history") == 0) + return buffer->num_history; + else if (string_strcasecmp (property, "text_search") == 0) + return buffer->text_search; + else if (string_strcasecmp (property, "text_search_exact") == 0) + return buffer->text_search_exact; + else if (string_strcasecmp (property, "text_search_regex") == 0) + return buffer->text_search_regex; + else if (string_strcasecmp (property, "text_search_where") == 0) + return buffer->text_search_where; + else if (string_strcasecmp (property, "text_search_found") == 0) + return buffer->text_search_found; return 0; } @@ -1058,39 +1079,39 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property) { const char *ptr_value; - if (buffer && property) - { - if (string_strcasecmp (property, "plugin") == 0) - return gui_buffer_get_plugin_name (buffer); - else if (string_strcasecmp (property, "name") == 0) - return buffer->name; - else if (string_strcasecmp (property, "full_name") == 0) - return buffer->full_name; - else if (string_strcasecmp (property, "short_name") == 0) - return gui_buffer_get_short_name (buffer); - else if (string_strcasecmp (property, "title") == 0) - return buffer->title; - else if (string_strcasecmp (property, "input") == 0) - return buffer->input_buffer; - else if (string_strcasecmp (property, "text_search_input") == 0) - return buffer->text_search_input; - else if (string_strcasecmp (property, "highlight_words") == 0) - return buffer->highlight_words; - else if (string_strcasecmp (property, "highlight_regex") == 0) - return buffer->highlight_regex; - else if (string_strcasecmp (property, "highlight_tags_restrict") == 0) - return buffer->highlight_tags_restrict; - else if (string_strcasecmp (property, "highlight_tags") == 0) - return buffer->highlight_tags; - else if (string_strcasecmp (property, "hotlist_max_level_nicks") == 0) - return hashtable_get_string (buffer->hotlist_max_level_nicks, "keys_values"); - else if (string_strncasecmp (property, "localvar_", 9) == 0) - { - ptr_value = (const char *)hashtable_get (buffer->local_variables, - property + 9); - if (ptr_value) - return ptr_value; - } + if (!buffer || !property) + return NULL; + + if (string_strcasecmp (property, "plugin") == 0) + return gui_buffer_get_plugin_name (buffer); + else if (string_strcasecmp (property, "name") == 0) + return buffer->name; + else if (string_strcasecmp (property, "full_name") == 0) + return buffer->full_name; + else if (string_strcasecmp (property, "short_name") == 0) + return gui_buffer_get_short_name (buffer); + else if (string_strcasecmp (property, "title") == 0) + return buffer->title; + else if (string_strcasecmp (property, "input") == 0) + return buffer->input_buffer; + else if (string_strcasecmp (property, "text_search_input") == 0) + return buffer->text_search_input; + else if (string_strcasecmp (property, "highlight_words") == 0) + return buffer->highlight_words; + else if (string_strcasecmp (property, "highlight_regex") == 0) + return buffer->highlight_regex; + else if (string_strcasecmp (property, "highlight_tags_restrict") == 0) + return buffer->highlight_tags_restrict; + else if (string_strcasecmp (property, "highlight_tags") == 0) + return buffer->highlight_tags; + else if (string_strcasecmp (property, "hotlist_max_level_nicks") == 0) + return hashtable_get_string (buffer->hotlist_max_level_nicks, "keys_values"); + else if (string_strncasecmp (property, "localvar_", 9) == 0) + { + ptr_value = (const char *)hashtable_get (buffer->local_variables, + property + 9); + if (ptr_value) + return ptr_value; } return NULL; @@ -1103,15 +1124,15 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property) void * gui_buffer_get_pointer (struct t_gui_buffer *buffer, const char *property) { - if (buffer && property) - { - if (string_strcasecmp (property, "plugin") == 0) - return buffer->plugin; - else if (string_strcasecmp (property, "text_search_regex_compiled") == 0) - return buffer->text_search_regex_compiled; - else if (string_strcasecmp (property, "highlight_regex_compiled") == 0) - return buffer->highlight_regex_compiled; - } + if (!buffer || !property) + return NULL; + + if (string_strcasecmp (property, "plugin") == 0) + return buffer->plugin; + else if (string_strcasecmp (property, "text_search_regex_compiled") == 0) + return buffer->text_search_regex_compiled; + else if (string_strcasecmp (property, "highlight_regex_compiled") == 0) + return buffer->highlight_regex_compiled; return NULL; } @@ -1123,6 +1144,9 @@ gui_buffer_get_pointer (struct t_gui_buffer *buffer, const char *property) void gui_buffer_ask_chat_refresh (struct t_gui_buffer *buffer, int refresh) { + if (!buffer) + return; + if (refresh > buffer->chat_refresh_needed) buffer->chat_refresh_needed = refresh; } @@ -1134,18 +1158,18 @@ gui_buffer_ask_chat_refresh (struct t_gui_buffer *buffer, int refresh) void gui_buffer_set_name (struct t_gui_buffer *buffer, const char *name) { - if (name && name[0]) - { - if (buffer->name) - free (buffer->name); - buffer->name = strdup (name); - gui_buffer_build_full_name (buffer); + if (!buffer || !name || !name[0]) + return; - gui_buffer_local_var_add (buffer, "name", name); + if (buffer->name) + free (buffer->name); + buffer->name = strdup (name); + gui_buffer_build_full_name (buffer); - (void) hook_signal_send ("buffer_renamed", - WEECHAT_HOOK_SIGNAL_POINTER, buffer); - } + gui_buffer_local_var_add (buffer, "name", name); + + (void) hook_signal_send ("buffer_renamed", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); } /* @@ -1155,6 +1179,9 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, const char *name) void gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name) { + if (!buffer) + return; + if (buffer->short_name) { free (buffer->short_name); @@ -1178,7 +1205,7 @@ gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name) void gui_buffer_set_type (struct t_gui_buffer *buffer, enum t_gui_buffer_type type) { - if (buffer->type == type) + if (!buffer || (buffer->type == type)) return; gui_line_free_all (buffer); @@ -1200,6 +1227,9 @@ gui_buffer_set_type (struct t_gui_buffer *buffer, enum t_gui_buffer_type type) void gui_buffer_set_title (struct t_gui_buffer *buffer, const char *new_title) { + if (!buffer) + return; + if (buffer->title) free (buffer->title); buffer->title = (new_title && new_title[0]) ? strdup (new_title) : NULL; @@ -1216,6 +1246,9 @@ void gui_buffer_set_time_for_each_line (struct t_gui_buffer *buffer, int time_for_each_line) { + if (!buffer) + return; + buffer->time_for_each_line = (time_for_each_line) ? 1 : 0; gui_buffer_ask_chat_refresh (buffer, 2); } @@ -1227,6 +1260,9 @@ gui_buffer_set_time_for_each_line (struct t_gui_buffer *buffer, void gui_buffer_set_nicklist (struct t_gui_buffer *buffer, int nicklist) { + if (!buffer) + return; + buffer->nicklist = (nicklist) ? 1 : 0; gui_window_ask_refresh (1); } @@ -1239,6 +1275,9 @@ void gui_buffer_set_nicklist_case_sensitive (struct t_gui_buffer *buffer, int case_sensitive) { + if (!buffer) + return; + buffer->nicklist_case_sensitive = (case_sensitive) ? 1 : 0; } @@ -1250,6 +1289,9 @@ void gui_buffer_set_nicklist_display_groups (struct t_gui_buffer *buffer, int display_groups) { + if (!buffer) + return; + buffer->nicklist_display_groups = (display_groups) ? 1 : 0; buffer->nicklist_visible_count = 0; gui_nicklist_compute_visible_count (buffer, buffer->nicklist_root); @@ -1264,6 +1306,9 @@ void gui_buffer_set_highlight_words (struct t_gui_buffer *buffer, const char *new_highlight_words) { + if (!buffer) + return; + if (buffer->highlight_words) free (buffer->highlight_words); buffer->highlight_words = (new_highlight_words && new_highlight_words[0]) ? @@ -1283,6 +1328,9 @@ gui_buffer_set_highlight_words_list (struct t_gui_buffer *buffer, const char *ptr_string; char *words; + if (!buffer) + return; + /* compute length */ length = 0; for (ptr_list_item = weelist_get (list, 0); ptr_list_item; @@ -1330,7 +1378,7 @@ gui_buffer_add_highlight_words (struct t_gui_buffer *buffer, int current_count, add_count, i; struct t_weelist *list; - if (!words_to_add) + if (!buffer || !words_to_add) return; list = weelist_new (); @@ -1375,7 +1423,7 @@ gui_buffer_remove_highlight_words (struct t_gui_buffer *buffer, int current_count, remove_count, i, j, to_remove; struct t_weelist *list; - if (!words_to_remove) + if (!buffer || !words_to_remove) return; list = weelist_new (); @@ -1421,6 +1469,9 @@ void gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer, const char *new_highlight_regex) { + if (!buffer) + return; + if (buffer->highlight_regex) { free (buffer->highlight_regex); @@ -1465,6 +1516,9 @@ gui_buffer_set_highlight_tags_restrict (struct t_gui_buffer *buffer, int i; char **tags_array; + if (!buffer) + return; + if (buffer->highlight_tags_restrict) { free (buffer->highlight_tags_restrict); @@ -1519,6 +1573,9 @@ gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, int i; char **tags_array; + if (!buffer) + return; + if (buffer->highlight_tags) { free (buffer->highlight_tags); @@ -1574,6 +1631,9 @@ gui_buffer_set_hotlist_max_level_nicks (struct t_gui_buffer *buffer, int nicks_count, value, i; long number; + if (!buffer) + return; + hashtable_remove_all (buffer->hotlist_max_level_nicks); if (new_hotlist_max_level_nicks && new_hotlist_max_level_nicks[0]) @@ -1615,7 +1675,7 @@ gui_buffer_add_hotlist_max_level_nicks (struct t_gui_buffer *buffer, int nicks_count, value, i; long number; - if (!nicks_to_add) + if (!buffer || !nicks_to_add) return; nicks = string_split (nicks_to_add, ",", 0, 0, &nicks_count); @@ -1652,7 +1712,7 @@ gui_buffer_remove_hotlist_max_level_nicks (struct t_gui_buffer *buffer, char **nicks, *pos; int nicks_count, i; - if (!nicks_to_remove) + if (!buffer || !nicks_to_remove) return; nicks = string_split (nicks_to_remove, ",", 0, 0, &nicks_count); @@ -1677,6 +1737,9 @@ void gui_buffer_set_input_get_unknown_commands (struct t_gui_buffer *buffer, int input_get_unknown_commands) { + if (!buffer) + return; + buffer->input_get_unknown_commands = (input_get_unknown_commands) ? 1 : 0; } @@ -1689,17 +1752,17 @@ gui_buffer_set_unread (struct t_gui_buffer *buffer) { int refresh; - if (buffer->type == GUI_BUFFER_TYPE_FORMATTED) - { - refresh = ((buffer->lines->last_read_line != NULL) - && (buffer->lines->last_read_line != buffer->lines->last_line)); + if (!buffer || (buffer->type != GUI_BUFFER_TYPE_FORMATTED)) + return; - buffer->lines->last_read_line = buffer->lines->last_line; - buffer->lines->first_line_not_read = (buffer->lines->last_read_line) ? 0 : 1; + refresh = ((buffer->lines->last_read_line != NULL) + && (buffer->lines->last_read_line != buffer->lines->last_line)); - if (refresh) - gui_buffer_ask_chat_refresh (buffer, 2); - } + buffer->lines->last_read_line = buffer->lines->last_line; + buffer->lines->first_line_not_read = (buffer->lines->last_read_line) ? 0 : 1; + + if (refresh) + gui_buffer_ask_chat_refresh (buffer, 2); } /* @@ -2036,6 +2099,9 @@ gui_buffer_add_value_num_displayed (struct t_gui_buffer *buffer, int value) { struct t_gui_buffer *ptr_buffer; + if (!buffer) + return; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -2505,6 +2571,9 @@ gui_buffer_close (struct t_gui_buffer *buffer) int index, i; struct t_gui_buffer_visited *ptr_buffer_visited; + if (!buffer) + return; + buffer->closing = 1; (void) hook_signal_send ("buffer_closing", @@ -2713,6 +2782,9 @@ gui_buffer_switch_by_number (struct t_gui_window *window, int number) { struct t_gui_buffer *ptr_buffer; + if (!window || !window->buffer) + return; + /* invalid buffer */ if ((number < 0) || (number == window->buffer->number)) return; @@ -2739,6 +2811,9 @@ gui_buffer_set_active_buffer (struct t_gui_buffer *buffer) struct t_gui_buffer *ptr_buffer; int active; + if (!buffer) + return; + active = 1; for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) @@ -2785,6 +2860,9 @@ gui_buffer_get_next_active_buffer (struct t_gui_buffer *buffer, { struct t_gui_buffer *ptr_buffer; + if (!buffer) + return NULL; + /* search after buffer */ for (ptr_buffer = buffer->next_buffer; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) @@ -2825,6 +2903,9 @@ gui_buffer_get_previous_active_buffer (struct t_gui_buffer *buffer, { struct t_gui_buffer *ptr_buffer; + if (!buffer) + return NULL; + /* search before buffer */ for (ptr_buffer = buffer->prev_buffer; ptr_buffer; ptr_buffer = ptr_buffer->prev_buffer) @@ -2975,6 +3056,9 @@ gui_buffer_move_to_number (struct t_gui_buffer *buffer, int number) auto_renumber = CONFIG_BOOLEAN(config_look_buffer_auto_renumber); + if (!buffer) + return; + /* nothing to do if auto renumber is ON and that there is only one buffer */ if (auto_renumber && (gui_buffers == last_gui_buffer)) return; @@ -3191,6 +3275,9 @@ gui_buffer_merge (struct t_gui_buffer *buffer, { struct t_gui_buffer *ptr_buffer, *ptr_first_buffer[2], *ptr_last_buffer[2]; + if (!buffer || !target_buffer) + return; + /* * nothing to do if: * - there is only one buffer @@ -3296,6 +3383,9 @@ gui_buffer_unmerge (struct t_gui_buffer *buffer, int number) int num_merged; struct t_gui_buffer *ptr_buffer, *ptr_new_active_buffer; + if (!buffer) + return; + /* nothing to do if there is only one buffer */ if (gui_buffers == last_gui_buffer) return; @@ -3570,6 +3660,9 @@ gui_buffer_sort_by_layout_number () void gui_buffer_undo_snap (struct t_gui_buffer *buffer) { + if (!buffer) + return; + if ((buffer->input_undo_snap)->data) { free ((buffer->input_undo_snap)->data); @@ -3592,6 +3685,9 @@ gui_buffer_undo_snap (struct t_gui_buffer *buffer) void gui_buffer_undo_snap_free (struct t_gui_buffer *buffer) { + if (!buffer) + return; + if ((buffer->input_undo_snap)->data) { free ((buffer->input_undo_snap)->data); @@ -3612,6 +3708,9 @@ gui_buffer_undo_add (struct t_gui_buffer *buffer) { struct t_gui_input_undo *new_undo; + if (!buffer) + return; + /* undo disabled by configuration */ if (CONFIG_INTEGER(config_look_input_undo_max) == 0) goto end; @@ -3692,6 +3791,9 @@ void gui_buffer_undo_free (struct t_gui_buffer *buffer, struct t_gui_input_undo *undo) { + if (!buffer || !undo) + return; + /* update current undo if needed */ if (buffer->ptr_input_undo == undo) { @@ -3727,6 +3829,9 @@ gui_buffer_undo_free (struct t_gui_buffer *buffer, void gui_buffer_undo_free_all (struct t_gui_buffer *buffer) { + if (!buffer) + return; + gui_buffer_undo_snap_free (buffer); while (buffer->input_undo) diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index c81f9d16e..5d4e2270b 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -465,41 +465,41 @@ gui_window_scroll_switch (struct t_gui_window *window, { struct t_gui_window_scroll *ptr_scroll, *new_scroll; - if (window && buffer) - { - ptr_scroll = gui_window_scroll_search (window, buffer); + if (!window || !buffer) + return; - /* scroll is already selected (first in list)? */ - if (ptr_scroll && (ptr_scroll == window->scroll)) - return; + ptr_scroll = gui_window_scroll_search (window, buffer); - if (ptr_scroll) - { - /* scroll found, move it in first position */ - if (ptr_scroll->prev_scroll) - (ptr_scroll->prev_scroll)->next_scroll = ptr_scroll->next_scroll; - if (ptr_scroll->next_scroll) - (ptr_scroll->next_scroll)->prev_scroll = ptr_scroll->prev_scroll; - (window->scroll)->prev_scroll = ptr_scroll; - ptr_scroll->prev_scroll = NULL; - ptr_scroll->next_scroll = window->scroll; - window->scroll = ptr_scroll; - } - else + /* scroll is already selected (first in list)? */ + if (ptr_scroll && (ptr_scroll == window->scroll)) + return; + + if (ptr_scroll) + { + /* scroll found, move it in first position */ + if (ptr_scroll->prev_scroll) + (ptr_scroll->prev_scroll)->next_scroll = ptr_scroll->next_scroll; + if (ptr_scroll->next_scroll) + (ptr_scroll->next_scroll)->prev_scroll = ptr_scroll->prev_scroll; + (window->scroll)->prev_scroll = ptr_scroll; + ptr_scroll->prev_scroll = NULL; + ptr_scroll->next_scroll = window->scroll; + window->scroll = ptr_scroll; + } + else + { + /* scroll not found, create one and add it at first position */ + new_scroll = malloc (sizeof (*new_scroll)); + if (new_scroll) { - /* scroll not found, create one and add it at first position */ - new_scroll = malloc (sizeof (*new_scroll)); - if (new_scroll) - { - gui_window_scroll_init (new_scroll, buffer); - new_scroll->next_scroll = window->scroll; - (window->scroll)->prev_scroll = new_scroll; - window->scroll = new_scroll; - } + gui_window_scroll_init (new_scroll, buffer); + new_scroll->next_scroll = window->scroll; + (window->scroll)->prev_scroll = new_scroll; + window->scroll = new_scroll; } - - gui_window_scroll_remove_not_scrolled (window); } + + gui_window_scroll_remove_not_scrolled (window); } /* @@ -512,12 +512,12 @@ gui_window_scroll_remove_buffer (struct t_gui_window *window, { struct t_gui_window_scroll *ptr_scroll; - if (window && buffer) - { - ptr_scroll = gui_window_scroll_search (window, buffer); - if (ptr_scroll) - gui_window_scroll_free (window, ptr_scroll); - } + if (!window || !buffer) + return; + + ptr_scroll = gui_window_scroll_search (window, buffer); + if (ptr_scroll) + gui_window_scroll_free (window, ptr_scroll); } /* @@ -738,37 +738,37 @@ gui_window_search_with_buffer (struct t_gui_buffer *buffer) int gui_window_get_integer (struct t_gui_window *window, const char *property) { - if (window && property) - { - if (string_strcasecmp (property, "number") == 0) - return window->number; - if (string_strcasecmp (property, "win_x") == 0) - return window->win_x; - if (string_strcasecmp (property, "win_y") == 0) - return window->win_y; - if (string_strcasecmp (property, "win_width") == 0) - return window->win_width; - if (string_strcasecmp (property, "win_height") == 0) - return window->win_height; - if (string_strcasecmp (property, "win_width_pct") == 0) - return window->win_width_pct; - if (string_strcasecmp (property, "win_height_pct") == 0) - return window->win_height_pct; - if (string_strcasecmp (property, "win_chat_x") == 0) - return window->win_chat_x; - if (string_strcasecmp (property, "win_chat_y") == 0) - return window->win_chat_y; - if (string_strcasecmp (property, "win_chat_width") == 0) - return window->win_chat_width; - if (string_strcasecmp (property, "win_chat_height") == 0) - return window->win_chat_height; - if (string_strcasecmp (property, "first_line_displayed") == 0) - return window->scroll->first_line_displayed; - if (string_strcasecmp (property, "scrolling") == 0) - return window->scroll->scrolling; - if (string_strcasecmp (property, "lines_after") == 0) - return window->scroll->lines_after; - } + if (!window || !property) + return 0; + + if (string_strcasecmp (property, "number") == 0) + return window->number; + if (string_strcasecmp (property, "win_x") == 0) + return window->win_x; + if (string_strcasecmp (property, "win_y") == 0) + return window->win_y; + if (string_strcasecmp (property, "win_width") == 0) + return window->win_width; + if (string_strcasecmp (property, "win_height") == 0) + return window->win_height; + if (string_strcasecmp (property, "win_width_pct") == 0) + return window->win_width_pct; + if (string_strcasecmp (property, "win_height_pct") == 0) + return window->win_height_pct; + if (string_strcasecmp (property, "win_chat_x") == 0) + return window->win_chat_x; + if (string_strcasecmp (property, "win_chat_y") == 0) + return window->win_chat_y; + if (string_strcasecmp (property, "win_chat_width") == 0) + return window->win_chat_width; + if (string_strcasecmp (property, "win_chat_height") == 0) + return window->win_chat_height; + if (string_strcasecmp (property, "first_line_displayed") == 0) + return window->scroll->first_line_displayed; + if (string_strcasecmp (property, "scrolling") == 0) + return window->scroll->scrolling; + if (string_strcasecmp (property, "lines_after") == 0) + return window->scroll->lines_after; return 0; } @@ -780,9 +780,8 @@ gui_window_get_integer (struct t_gui_window *window, const char *property) const char * gui_window_get_string (struct t_gui_window *window, const char *property) { - if (window && property) - { - } + if (!window || !property) + return NULL; return NULL; } @@ -817,6 +816,9 @@ void gui_window_set_layout_plugin_name (struct t_gui_window *window, const char *plugin_name) { + if (!window) + return; + if (window->layout_plugin_name) { free (window->layout_plugin_name); @@ -835,6 +837,9 @@ void gui_window_set_layout_buffer_name (struct t_gui_window *window, const char *buffer_name) { + if (!window) + return; + if (window->layout_buffer_name) { free (window->layout_buffer_name); @@ -852,8 +857,11 @@ gui_window_set_layout_buffer_name (struct t_gui_window *window, void gui_window_coords_init_line (struct t_gui_window *window, int line) { - if (!window->coords || (line < 0) || (line >= window->coords_size)) + if (!window || !window->coords || (line < 0) + || (line >= window->coords_size)) + { return; + } window->coords[line].line = NULL; window->coords[line].data = NULL; @@ -876,7 +884,7 @@ gui_window_coords_remove_line (struct t_gui_window *window, { int i; - if (!window->coords) + if (!window || !window->coords) return; for (i = 0; i < window->coords_size; i++) @@ -897,7 +905,7 @@ gui_window_coords_remove_line_data (struct t_gui_window *window, { int i; - if (!window->coords) + if (!window || !window->coords) return; for (i = 0; i < window->coords_size; i++) @@ -919,6 +927,9 @@ gui_window_coords_alloc (struct t_gui_window *window) { int i; + if (!window) + return; + if (window->coords && (window->coords_size != window->win_chat_height)) { free (window->coords); @@ -947,6 +958,9 @@ gui_window_free (struct t_gui_window *window) struct t_gui_window *ptr_win, *old_current_window; int i; + if (!window) + return; + old_current_window = gui_current_window; (void) hook_signal_send ("window_closing", @@ -1021,7 +1035,7 @@ gui_window_free (struct t_gui_window *window) void gui_window_switch_previous (struct t_gui_window *window) { - if (!gui_init_ok) + if (!gui_init_ok || !window) return; gui_window_switch ((window->prev_window) ? @@ -1035,7 +1049,7 @@ gui_window_switch_previous (struct t_gui_window *window) void gui_window_switch_next (struct t_gui_window *window) { - if (!gui_init_ok) + if (!gui_init_ok || !window) return; gui_window_switch ((window->next_window) ? @@ -1068,7 +1082,7 @@ gui_window_switch_by_buffer (struct t_gui_window *window, int buffer_number) { struct t_gui_window *ptr_win; - if (!gui_init_ok) + if (!gui_init_ok || !window) return; ptr_win = (window->next_window) ? window->next_window : gui_windows; @@ -1098,7 +1112,7 @@ gui_window_scroll (struct t_gui_window *window, char *scroll) struct t_gui_line *ptr_line; struct tm *date_tmp, line_date, old_line_date; - if (!window->buffer->lines->first_line) + if (!window || !window->buffer->lines->first_line) return; direction = 1; @@ -1345,61 +1359,61 @@ gui_window_scroll_horiz (struct t_gui_window *window, char *scroll) char saved_char, *pos, *error; long number; - if (window->buffer->lines->first_line) - { - direction = 1; - number = 0; - percentage = 0; + if (!window || !window->buffer->lines->first_line) + return; - /* search direction */ - if (scroll[0] == '-') - { - direction = -1; - scroll++; - } - else if (scroll[0] == '+') - { - direction = +1; - scroll++; - } + direction = 1; + number = 0; + percentage = 0; - /* search number and percentage */ - pos = scroll; - while (pos && pos[0] && isdigit ((unsigned char)pos[0])) - { - pos++; - } - if (pos && (pos > scroll)) - { - percentage = (pos[0] == '%') ? 1 : 0; - saved_char = pos[0]; - pos[0] = '\0'; - error = NULL; - number = strtol (scroll, &error, 10); - if (!error || error[0]) - number = 0; - pos[0] = saved_char; - } + /* search direction */ + if (scroll[0] == '-') + { + direction = -1; + scroll++; + } + else if (scroll[0] == '+') + { + direction = +1; + scroll++; + } - /* for percentage, compute number of columns */ - if (percentage) - { - number = (window->win_chat_width * number) / 100; - } + /* search number and percentage */ + pos = scroll; + while (pos && pos[0] && isdigit ((unsigned char)pos[0])) + { + pos++; + } + if (pos && (pos > scroll)) + { + percentage = (pos[0] == '%') ? 1 : 0; + saved_char = pos[0]; + pos[0] = '\0'; + error = NULL; + number = strtol (scroll, &error, 10); + if (!error || error[0]) + number = 0; + pos[0] = saved_char; + } - /* number must be different from 0 */ - if (number == 0) - return; + /* for percentage, compute number of columns */ + if (percentage) + { + number = (window->win_chat_width * number) / 100; + } - /* do the horizontal scroll! */ - start_col = window->scroll->start_col + (number * direction); - if (start_col < 0) - start_col = 0; - if (start_col != window->scroll->start_col) - { - window->scroll->start_col = start_col; - gui_buffer_ask_chat_refresh (window->buffer, 2); - } + /* number must be different from 0 */ + if (number == 0) + return; + + /* do the horizontal scroll! */ + start_col = window->scroll->start_col + (number * direction); + if (start_col < 0) + start_col = 0; + if (start_col != window->scroll->start_col) + { + window->scroll->start_col = start_col; + gui_buffer_ask_chat_refresh (window->buffer, 2); } } @@ -1412,6 +1426,9 @@ gui_window_scroll_previous_highlight (struct t_gui_window *window) { struct t_gui_line *ptr_line; + if (!window) + return; + if ((window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { @@ -1447,6 +1464,9 @@ gui_window_scroll_next_highlight (struct t_gui_window *window) { struct t_gui_line *ptr_line; + if (!window) + return; + if ((window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) && (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED)) { @@ -1480,6 +1500,9 @@ gui_window_scroll_next_highlight (struct t_gui_window *window) void gui_window_scroll_unread (struct t_gui_window *window) { + if (!window) + return; + if (window->buffer->text_search == GUI_TEXT_SEARCH_DISABLED) { if (CONFIG_STRING(config_look_read_marker) && @@ -1519,6 +1542,9 @@ gui_window_search_text (struct t_gui_window *window) { struct t_gui_line *ptr_line; + if (!window) + return 0; + if (window->buffer->text_search == GUI_TEXT_SEARCH_BACKWARD) { if (window->buffer->lines->first_line @@ -1577,6 +1603,9 @@ void gui_window_search_start (struct t_gui_window *window, struct t_gui_line *text_search_start_line) { + if (!window) + return; + window->scroll->text_search_start_line = text_search_start_line; window->buffer->text_search = (window->buffer->type == GUI_BUFFER_TYPE_FORMATTED) ? @@ -1630,6 +1659,9 @@ gui_window_search_start (struct t_gui_window *window, void gui_window_search_restart (struct t_gui_window *window) { + if (!window) + return; + window->scroll->start_line = window->scroll->text_search_start_line; window->scroll->start_line_pos = 0; window->buffer->text_search = @@ -1658,6 +1690,9 @@ gui_window_search_restart (struct t_gui_window *window) void gui_window_search_end (struct t_gui_window *window) { + if (!window) + return; + window->buffer->text_search = GUI_TEXT_SEARCH_DISABLED; window->buffer->text_search = 0; if (window->buffer->text_search_regex_compiled) @@ -1686,6 +1721,9 @@ gui_window_search_end (struct t_gui_window *window) void gui_window_search_stop_here (struct t_gui_window *window) { + if (!window) + return; + gui_window_search_end (window); window->scroll->text_search_start_line = NULL; gui_buffer_ask_chat_refresh (window->buffer, 2); @@ -1698,6 +1736,9 @@ gui_window_search_stop_here (struct t_gui_window *window) void gui_window_search_stop (struct t_gui_window *window) { + if (!window) + return; + gui_window_search_end (window); window->scroll->start_line = window->scroll->text_search_start_line; window->scroll->start_line_pos = 0; @@ -1715,7 +1756,7 @@ gui_window_zoom (struct t_gui_window *window) { struct t_gui_layout *ptr_layout; - if (!gui_init_ok) + if (!gui_init_ok || !window) return; ptr_layout = gui_layout_search (GUI_LAYOUT_ZOOM); |