diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-01-28 07:12:01 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-01-28 07:12:01 +0100 |
commit | 311074077789f1d645c3d8c3df58f78a54412222 (patch) | |
tree | 3dd3489ae7c3ed36141478ec8cfb8accfdbe30df /src | |
parent | a62f8f6f75279396e218204a6ee8d58bd0b6995b (diff) | |
download | weechat-311074077789f1d645c3d8c3df58f78a54412222.zip |
core: use dynamic string in function gui_chat_build_string_message_tags
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui-chat.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 9cecf6121..8403760f7 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -613,39 +613,35 @@ gui_chat_build_string_prefix_message (struct t_gui_line *line) * Note: result must be freed after use. */ - char * gui_chat_build_string_message_tags (struct t_gui_line *line) { - int i, length; - char *buf; + int i; + char **string, *result; - length = 64 + 2; - if (line->data->message) - length += strlen (line->data->message); - for (i = 0; i < line->data->tags_count; i++) - { - length += strlen (line->data->tags_array[i]) + 1; - } - length += 2; + string = string_dyn_alloc (256); + if (!string) + return NULL; - buf = malloc (length); - buf[0] = '\0'; if (line->data->message) - strcat (buf, line->data->message); - strcat (buf, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - strcat (buf, " ["); - strcat (buf, GUI_COLOR(GUI_COLOR_CHAT_TAGS)); + string_dyn_concat (string, line->data->message, -1); + string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1); + string_dyn_concat (string, " [", -1); + string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_TAGS), -1); for (i = 0; i < line->data->tags_count; i++) { - strcat (buf, line->data->tags_array[i]); + string_dyn_concat (string, line->data->tags_array[i], -1); if (i < line->data->tags_count - 1) - strcat (buf, ","); + string_dyn_concat (string, ",", -1); } - strcat (buf, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - strcat (buf, "]"); + string_dyn_concat (string, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), -1); + string_dyn_concat (string, "]", -1); + + result = strdup (*string); + + string_dyn_free (string, 1); - return buf; + return result; } /* |