diff --git a/src/plugins/exec/exec-command.c b/src/plugins/exec/exec-command.c index ea9a1cd1b..5223387e7 100644 --- a/src/plugins/exec/exec-command.c +++ b/src/plugins/exec/exec-command.c @@ -656,7 +656,7 @@ exec_command_exec (const void *pointer, void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { - int i, length, count; + int i, count; char *text; struct t_exec_cmd *ptr_exec_cmd, *ptr_next_exec_cmd; @@ -680,11 +680,8 @@ exec_command_exec (const void *pointer, void *data, ptr_exec_cmd = exec_command_search_running_id (argv[2]); if (ptr_exec_cmd && ptr_exec_cmd->hook) { - length = strlen (argv_eol[3]) + 1 + 1; - text = malloc (length); - if (text) + if (weechat_asprintf (&text, "%s\n", argv_eol[3]) >= 0) { - snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } @@ -701,11 +698,8 @@ exec_command_exec (const void *pointer, void *data, { if (argc > 3) { - length = strlen (argv_eol[3]) + 1 + 1; - text = malloc (length); - if (text) + if (weechat_asprintf (&text, "%s\n", argv_eol[3]) >= 0) { - snprintf (text, length, "%s\n", argv_eol[3]); weechat_hook_set (ptr_exec_cmd->hook, "stdin", text); free (text); } diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c index 4f4eefce5..62f1a01a7 100644 --- a/src/plugins/exec/exec.c +++ b/src/plugins/exec/exec.c @@ -244,7 +244,6 @@ exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, { struct t_hashtable *options; char *line_color, *line2, str_number[32], str_tags[1024]; - int length; if (!exec_cmd || !line) return; @@ -293,12 +292,11 @@ exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, else { /* add line at the end of command, after a space */ - length = strlen (exec_cmd->pipe_command) + 1 + strlen (line_color) + 1; - line2 = malloc (length); - if (line2) + if (weechat_asprintf (&line2, + "%s %s", + exec_cmd->pipe_command, + line_color) >= 0) { - snprintf (line2, length, - "%s %s", exec_cmd->pipe_command, line_color); weechat_command_options (buffer, line2, options); free (line2); } @@ -310,12 +308,11 @@ exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, weechat_hashtable_set (options, "commands", "-"); if (exec_cmd->line_numbers) { - length = 32 + strlen (line_color) + 1; - line2 = malloc (length); - if (line2) + if (weechat_asprintf (&line2, + "%d. %s", + exec_cmd->output_line_nb, + line_color) >= 0) { - snprintf (line2, length, - "%d. %s", exec_cmd->output_line_nb, line_color); weechat_command_options (buffer, line2, options); free (line2); }