From 9779f56125e0bfd0d8b911a7715dfed607e06223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 17 Dec 2024 19:12:03 +0100 Subject: [PATCH] alias: replace calls to malloc by weechat_asprintf --- src/plugins/alias/alias.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index d865f39a6..a1faf37f9 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -418,7 +418,6 @@ void alias_hook_command (struct t_alias *alias) { char *str_priority_name, *str_completion; - int length; if (alias->hook) { @@ -431,10 +430,7 @@ alias_hook_command (struct t_alias *alias) * is greater than default one (1000), so the alias is executed before a * command (if a command with same name exists in core or in another plugin) */ - length = strlen (alias->name) + 16 + 1; - str_priority_name = malloc (length); - if (str_priority_name) - snprintf (str_priority_name, length, "2000|%s", alias->name); + weechat_asprintf (&str_priority_name, "2000|%s", alias->name); /* * if alias has no custom completion, then default is to complete with @@ -444,21 +440,19 @@ alias_hook_command (struct t_alias *alias) str_completion = NULL; if (!alias->completion) { - length = 2 + strlen (alias->command) + 1; - str_completion = malloc (length); - if (str_completion) - { - snprintf (str_completion, length, "%%%%%s", - (weechat_string_is_command_char (alias->command)) ? - weechat_utf8_next_char (alias->command) : alias->command); - } + weechat_asprintf ( + &str_completion, + "%%%%%s", + (weechat_string_is_command_char (alias->command)) ? + weechat_utf8_next_char (alias->command) : alias->command); } - alias->hook = weechat_hook_command ((str_priority_name) ? str_priority_name : alias->name, - alias->command, - NULL, NULL, - (str_completion) ? str_completion : alias->completion, - &alias_cb, alias, NULL); + alias->hook = weechat_hook_command ( + (str_priority_name) ? str_priority_name : alias->name, + alias->command, + NULL, NULL, + (str_completion) ? str_completion : alias->completion, + &alias_cb, alias, NULL); free (str_priority_name); free (str_completion);