1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 01:03:14 +02:00

core: replace calls to malloc by string_asprintf

This commit is contained in:
Sébastien Helleu
2024-12-17 19:11:02 +01:00
parent 8f43dceedf
commit 818a4c95a9
22 changed files with 409 additions and 623 deletions
+10 -18
View File
@@ -51,7 +51,6 @@ struct t_config_section *plugin_config_section_desc = NULL;
struct t_config_option *
plugin_config_search (const char *plugin_name, const char *option_name)
{
int length;
char *option_full_name;
struct t_config_option *ptr_option;
@@ -60,12 +59,10 @@ plugin_config_search (const char *plugin_name, const char *option_name)
ptr_option = NULL;
length = strlen (plugin_name) + 1 + strlen (option_name) + 1;
option_full_name = malloc (length);
if (option_full_name)
if (string_asprintf (&option_full_name,
"%s.%s",
plugin_name, option_name) >= 0)
{
snprintf (option_full_name, length, "%s.%s",
plugin_name, option_name);
ptr_option = config_file_search_option (plugin_config_file,
plugin_config_section_var,
option_full_name);
@@ -113,17 +110,15 @@ int
plugin_config_set (const char *plugin_name, const char *option_name,
const char *value)
{
int length, rc;
int rc;
char *option_full_name;
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
length = strlen (plugin_name) + 1 + strlen (option_name) + 1;
option_full_name = malloc (length);
if (option_full_name)
if (string_asprintf (&option_full_name,
"%s.%s",
plugin_name, option_name) >= 0)
{
snprintf (option_full_name, length, "%s.%s",
plugin_name, option_name);
rc = plugin_config_set_internal (option_full_name, value);
free (option_full_name);
}
@@ -200,15 +195,12 @@ void
plugin_config_set_desc (const char *plugin_name, const char *option_name,
const char *description)
{
int length;
char *option_full_name;
length = strlen (plugin_name) + 1 + strlen (option_name) + 1;
option_full_name = malloc (length);
if (option_full_name)
if (string_asprintf (&option_full_name,
"%s.%s",
plugin_name, option_name) >= 0)
{
snprintf (option_full_name, length, "%s.%s",
plugin_name, option_name);
plugin_config_set_desc_internal (option_full_name, description);
free (option_full_name);
}
+39 -47
View File
@@ -1053,7 +1053,7 @@ plugin_auto_load (char *force_plugin_autoload,
struct t_plugin_args plugin_args;
struct t_arraylist *arraylist;
struct t_hashtable *options;
int length, i;
int i;
plugin_args.argc = argc;
plugin_args.argv = argv;
@@ -1106,23 +1106,20 @@ plugin_auto_load (char *force_plugin_autoload,
extra_libdir = getenv (WEECHAT_EXTRA_LIBDIR);
if (extra_libdir && extra_libdir[0])
{
length = strlen (extra_libdir) + 16 + 1;
dir_name = malloc (length);
snprintf (dir_name, length, "%s/plugins", extra_libdir);
dir_exec_on_files (dir_name, 1, 0,
&plugin_auto_load_file, &plugin_args);
free (dir_name);
if (string_asprintf (&dir_name, "%s/plugins", extra_libdir) >= 0)
{
dir_exec_on_files (dir_name, 1, 0,
&plugin_auto_load_file, &plugin_args);
free (dir_name);
}
}
}
/* auto-load plugins in WeeChat global lib dir */
if (load_from_lib_dir)
{
length = strlen (WEECHAT_LIBDIR) + 16 + 1;
dir_name = malloc (length);
if (dir_name)
if (string_asprintf (&dir_name,"%s/plugins", WEECHAT_LIBDIR) >= 0)
{
snprintf (dir_name, length, "%s/plugins", WEECHAT_LIBDIR);
dir_exec_on_files (dir_name, 1, 0,
&plugin_auto_load_file, &plugin_args);
free (dir_name);
@@ -1353,48 +1350,43 @@ plugin_reload_name (const char *name, int argc, char **argv)
void
plugin_display_short_list ()
{
const char *plugins_loaded;
char *buf;
int length;
char **buf;
struct t_weechat_plugin *ptr_plugin;
struct t_weelist *list;
struct t_weelist_item *ptr_item;
if (weechat_plugins)
if (!weechat_plugins)
return;
list = weelist_new ();
if (!list)
return;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
list = weelist_new ();
if (list)
{
plugins_loaded = _("Plugins loaded:");
length = strlen (plugins_loaded) + 1;
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
length += strlen (ptr_plugin->name) + 2;
weelist_add (list, ptr_plugin->name, WEECHAT_LIST_POS_SORT, NULL);
}
length++;
buf = malloc (length);
if (buf)
{
strcpy (buf, plugins_loaded);
strcat (buf, " ");
for (ptr_item = list->items; ptr_item;
ptr_item = ptr_item->next_item)
{
strcat (buf, ptr_item->data);
if (ptr_item->next_item)
strcat (buf, ", ");
}
gui_chat_printf (NULL, "%s", buf);
free (buf);
}
weelist_free (list);
}
weelist_add (list, ptr_plugin->name, WEECHAT_LIST_POS_SORT, NULL);
}
buf = string_dyn_alloc (256);
if (!buf)
{
weelist_free (list);
return;
}
string_dyn_concat (buf, _("Plugins loaded:"), -1);
string_dyn_concat (buf, " ", -1);
for (ptr_item = list->items; ptr_item; ptr_item = ptr_item->next_item)
{
string_dyn_concat (buf, ptr_item->data, -1);
if (ptr_item->next_item)
string_dyn_concat (buf, ", ", -1);
}
gui_chat_printf (NULL, "%s", *buf);
string_dyn_free (buf, 1);
weelist_free (list);
}
/*