diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-18 13:38:05 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-18 13:38:05 +0200 |
commit | 08e110c8357d043b0882145d3520f7c0e7c4d5d4 (patch) | |
tree | 8bdc84a0198c00a2fb02a0d09624350fb580229c | |
parent | 2c8657826f0886cb76855c0f539c4ac1ed2806c4 (diff) | |
download | weechat-08e110c8357d043b0882145d3520f7c0e7c4d5d4.zip |
core: use dynamic string in function gui_buffer_set_highlight_words_list
-rw-r--r-- | src/gui/gui-buffer.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index df8acfc27..612503603 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1630,46 +1630,34 @@ gui_buffer_set_highlight_words_list (struct t_gui_buffer *buffer, struct t_weelist *list) { struct t_weelist_item *ptr_list_item; - int length; const char *ptr_string; - char *words; + char **words; if (!buffer) return; - /* compute length */ - length = 0; - for (ptr_list_item = weelist_get (list, 0); ptr_list_item; - ptr_list_item = weelist_next (ptr_list_item)) - { - ptr_string = weelist_string (ptr_list_item); - if (ptr_string) - length += strlen (ptr_string) + 1; - } - length += 2; /* '\n' + '\0' */ - - /* allocate memory */ - words = malloc (length); + words = string_dyn_alloc (64); if (!words) return; - /* build string */ - words[0] = '\0'; - for (ptr_list_item = weelist_get (list, 0); ptr_list_item; - ptr_list_item = weelist_next (ptr_list_item)) + if (list) { - ptr_string = weelist_string (ptr_list_item); - if (ptr_string) + for (ptr_list_item = weelist_get (list, 0); ptr_list_item; + ptr_list_item = weelist_next (ptr_list_item)) { - strcat (words, ptr_string); - if (weelist_next (ptr_list_item)) - strcat (words, ","); + ptr_string = weelist_string (ptr_list_item); + if (ptr_string) + { + if (*words[0]) + string_dyn_concat (words, ",", -1); + string_dyn_concat (words, ptr_string, -1); + } } } - gui_buffer_set_highlight_words (buffer, words); + gui_buffer_set_highlight_words (buffer, *words); - free (words); + string_dyn_free (words, 1); } /* |