mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
fset: replace calls to malloc by weechat_asprintf
This commit is contained in:
@@ -896,7 +896,7 @@ int
|
||||
fset_buffer_display_option_predefined_format (struct t_fset_option *fset_option)
|
||||
{
|
||||
int selected_line, value_undef, value_changed, format_number;
|
||||
int add_quotes, add_quotes_parent, length_value;
|
||||
int add_quotes, add_quotes_parent;
|
||||
char str_marked[128], str_name[4096], str_type[128], *str_value;
|
||||
char str_color_line[128], str_color_value[128], str_color_quotes[128];
|
||||
char str_color_name[512];
|
||||
@@ -1011,43 +1011,39 @@ fset_buffer_display_option_predefined_format (struct t_fset_option *fset_option)
|
||||
fset_option->value,
|
||||
str_color_quotes);
|
||||
}
|
||||
length_value = (fset_option->value) ?
|
||||
strlen (fset_option->value) + 256 : 4096;
|
||||
str_value = malloc (length_value);
|
||||
if (str_value)
|
||||
if (value_undef && fset_option->parent_value)
|
||||
{
|
||||
if (value_undef && fset_option->parent_value)
|
||||
{
|
||||
add_quotes_parent = (fset_option->parent_value && (fset_option->type == FSET_OPTION_TYPE_STRING)) ? 1 : 0;
|
||||
snprintf (str_value, length_value,
|
||||
"%s%s%s%s%s%s%s -> %s%s%s%s%s%s%s",
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_value,
|
||||
(fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
weechat_color ("default"),
|
||||
(add_quotes_parent) ? weechat_color (weechat_config_string (fset_config_color_quotes[selected_line])) : "",
|
||||
(add_quotes_parent) ? "\"" : "",
|
||||
weechat_color (weechat_config_string (fset_config_color_parent_value[selected_line])),
|
||||
(fset_option->parent_value) ? fset_option->parent_value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes_parent) ? weechat_color (weechat_config_string (fset_config_color_quotes[selected_line])) : "",
|
||||
(add_quotes_parent) ? "\"" : "",
|
||||
str_color_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (str_value, length_value,
|
||||
"%s%s%s%s%s%s%s",
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_value,
|
||||
(fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_name);
|
||||
}
|
||||
add_quotes_parent = (fset_option->parent_value && (fset_option->type == FSET_OPTION_TYPE_STRING)) ? 1 : 0;
|
||||
weechat_asprintf (
|
||||
&str_value,
|
||||
"%s%s%s%s%s%s%s -> %s%s%s%s%s%s%s",
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_value,
|
||||
(fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
weechat_color ("default"),
|
||||
(add_quotes_parent) ? weechat_color (weechat_config_string (fset_config_color_quotes[selected_line])) : "",
|
||||
(add_quotes_parent) ? "\"" : "",
|
||||
weechat_color (weechat_config_string (fset_config_color_parent_value[selected_line])),
|
||||
(fset_option->parent_value) ? fset_option->parent_value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes_parent) ? weechat_color (weechat_config_string (fset_config_color_quotes[selected_line])) : "",
|
||||
(add_quotes_parent) ? "\"" : "",
|
||||
str_color_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_asprintf (
|
||||
&str_value,
|
||||
"%s%s%s%s%s%s%s",
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_value,
|
||||
(fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL,
|
||||
(add_quotes) ? str_color_quotes : "",
|
||||
(add_quotes) ? "\"" : "",
|
||||
str_color_name);
|
||||
}
|
||||
|
||||
weechat_printf_y (
|
||||
|
||||
@@ -230,7 +230,6 @@ void
|
||||
fset_option_add_option_in_hashtable (struct t_hashtable *hashtable,
|
||||
struct t_fset_option *fset_option)
|
||||
{
|
||||
int length;
|
||||
char *value;
|
||||
|
||||
weechat_hashtable_set (hashtable, "file", fset_option->file);
|
||||
@@ -251,19 +250,10 @@ fset_option_add_option_in_hashtable (struct t_hashtable *hashtable,
|
||||
weechat_hashtable_set (hashtable, "value", fset_option->value);
|
||||
if (fset_option->value && (fset_option->type == FSET_OPTION_TYPE_STRING))
|
||||
{
|
||||
length = 1 + strlen (fset_option->value) + 1 + 1;
|
||||
value = malloc (length);
|
||||
if (value)
|
||||
{
|
||||
snprintf (value, length, "\"%s\"", fset_option->value);
|
||||
weechat_hashtable_set (hashtable, "quoted_value", value);
|
||||
free (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_hashtable_set (hashtable,
|
||||
"quoted_value", fset_option->value);
|
||||
}
|
||||
weechat_asprintf (&value, "\"%s\"", fset_option->value);
|
||||
weechat_hashtable_set (hashtable, "quoted_value",
|
||||
(value) ? value : fset_option->value);
|
||||
free (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -435,7 +425,7 @@ fset_option_set_values (struct t_fset_option *fset_option,
|
||||
const char **ptr_string_values;
|
||||
void *ptr_default_value, *ptr_value;
|
||||
struct t_config_option *ptr_parent_option;
|
||||
int length, *ptr_type, *ptr_min, *ptr_max;
|
||||
int *ptr_type, *ptr_min, *ptr_max;
|
||||
char str_value[64], str_allowed_values[4096];
|
||||
|
||||
/* file */
|
||||
@@ -459,17 +449,11 @@ fset_option_set_values (struct t_fset_option *fset_option,
|
||||
/* name */
|
||||
free (fset_option->name);
|
||||
fset_option->name = NULL;
|
||||
length = strlen (ptr_config_name) + 1 +
|
||||
strlen (ptr_section_name) + 1 +
|
||||
strlen (ptr_option_name) + 1;
|
||||
fset_option->name = malloc (length);
|
||||
if (fset_option->name)
|
||||
{
|
||||
snprintf (fset_option->name, length, "%s.%s.%s",
|
||||
ptr_config_name,
|
||||
ptr_section_name,
|
||||
ptr_option_name);
|
||||
}
|
||||
weechat_asprintf (&fset_option->name,
|
||||
"%s.%s.%s",
|
||||
ptr_config_name,
|
||||
ptr_section_name,
|
||||
ptr_option_name);
|
||||
|
||||
/* parent name */
|
||||
free (fset_option->parent_name);
|
||||
@@ -1184,7 +1168,7 @@ fset_option_set (struct t_fset_option *fset_option,
|
||||
struct t_gui_buffer *buffer,
|
||||
int set_mode)
|
||||
{
|
||||
int use_mute, add_quotes, length_input, input_pos;
|
||||
int use_mute, add_quotes, input_pos;
|
||||
char *ptr_value, *str_input, str_pos[32];
|
||||
char empty_value[1] = { '\0' };
|
||||
|
||||
@@ -1199,20 +1183,19 @@ fset_option_set (struct t_fset_option *fset_option,
|
||||
else
|
||||
ptr_value = (fset_option->value) ? fset_option->value : empty_value;
|
||||
|
||||
length_input = 64 + strlen (fset_option->name) + strlen (ptr_value) + 1;
|
||||
str_input = malloc (length_input);
|
||||
if (!str_input)
|
||||
return;
|
||||
|
||||
use_mute = weechat_config_boolean (fset_config_look_use_mute);
|
||||
add_quotes = (fset_option->type == FSET_OPTION_TYPE_STRING) ? 1 : 0;
|
||||
snprintf (str_input, length_input,
|
||||
"%s/set %s %s%s%s",
|
||||
(use_mute) ? "/mute " : "",
|
||||
fset_option->name,
|
||||
(add_quotes) ? "\"" : "",
|
||||
ptr_value,
|
||||
(add_quotes) ? "\"" : "");
|
||||
if (weechat_asprintf (
|
||||
&str_input,
|
||||
"%s/set %s %s%s%s",
|
||||
(use_mute) ? "/mute " : "",
|
||||
fset_option->name,
|
||||
(add_quotes) ? "\"" : "",
|
||||
ptr_value,
|
||||
(add_quotes) ? "\"" : "") < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
weechat_buffer_set (buffer, "input", str_input);
|
||||
input_pos = ((use_mute) ? 6 : 0) + /* "/mute " */
|
||||
5 + /* "/set " */
|
||||
|
||||
Reference in New Issue
Block a user