1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

logger: replace calls to malloc by weechat_asprintf

This commit is contained in:
Sébastien Helleu
2024-12-17 20:43:23 +01:00
parent 45509e1cd1
commit 7226b005e9
3 changed files with 15 additions and 36 deletions
+2 -7
View File
@@ -191,21 +191,16 @@ logger_backlog_group_messages (struct t_arraylist *lines)
if (message)
{
new_message = malloc (strlen (ptr_line) + 1 + strlen (message) + 1);
if (!new_message)
if (weechat_asprintf (&new_message, "%s\n%s", ptr_line, message) < 0)
goto error;
strcpy (new_message, ptr_line);
strcat (new_message, "\n");
strcat (new_message, message);
free (message);
message = new_message;
}
else
{
message = malloc (strlen (ptr_line) + 1);
message = strdup (ptr_line);
if (!message)
goto error;
strcpy (message, ptr_line);
}
time_found = 0;
+6 -11
View File
@@ -167,12 +167,8 @@ logger_tail_file (const char *filename, int lines)
pos_eol++;
if (part_of_line)
{
line = malloc ((strlen (pos_eol) +
strlen (part_of_line) + 1));
if (!line)
if (weechat_asprintf (&line, "%s%s", pos_eol, part_of_line) < 0)
goto error;
strcpy (line, pos_eol);
strcat (line, part_of_line);
free (part_of_line);
part_of_line = NULL;
weechat_arraylist_insert (list_lines, 0, line);
@@ -193,20 +189,19 @@ logger_tail_file (const char *filename, int lines)
*/
if (part_of_line)
{
new_part_of_line = malloc (strlen (buf) + strlen (part_of_line) + 1);
if (!new_part_of_line)
if (weechat_asprintf (&new_part_of_line,
"%s%s", buf, part_of_line) < 0)
{
goto error;
strcpy (new_part_of_line, buf);
strcat (new_part_of_line, part_of_line);
}
free (part_of_line);
part_of_line = new_part_of_line;
}
else
{
part_of_line = malloc (strlen (buf) + 1);
part_of_line = strdup (buf);
if (!part_of_line)
goto error;
strcpy (part_of_line, buf);
}
ptr_buf = NULL;
}
+7 -18
View File
@@ -202,7 +202,6 @@ logger_build_option_name (struct t_gui_buffer *buffer)
{
const char *plugin_name, *name;
char *option_name;
int length;
if (!buffer)
return NULL;
@@ -210,12 +209,7 @@ logger_build_option_name (struct t_gui_buffer *buffer)
plugin_name = weechat_buffer_get_string (buffer, "plugin");
name = weechat_buffer_get_string (buffer, "name");
length = strlen (plugin_name) + 1 + strlen (name) + 1;
option_name = malloc (length);
if (!option_name)
return NULL;
snprintf (option_name, length, "%s.%s", plugin_name, name);
weechat_asprintf (&option_name, "%s.%s", plugin_name, name);
return option_name;
}
@@ -450,7 +444,6 @@ logger_get_filename (struct t_gui_buffer *buffer)
{
char *res, *mask_expanded, *file_path, *dir_separator;
const char *mask;
int length;
res = NULL;
mask_expanded = NULL;
@@ -483,16 +476,12 @@ logger_get_filename (struct t_gui_buffer *buffer)
goto end;
/* build string with path + mask */
length = strlen (file_path) + strlen (dir_separator) +
strlen (mask_expanded) + 1;
res = malloc (length);
if (res)
{
snprintf (res, length, "%s%s%s",
file_path,
(file_path[strlen (file_path) - 1] == dir_separator[0]) ? "" : dir_separator,
mask_expanded);
}
weechat_asprintf (
&res,
"%s%s%s",
file_path,
(file_path[strlen (file_path) - 1] == dir_separator[0]) ? "" : dir_separator,
mask_expanded);
end:
free (dir_separator);