summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-03-23 23:00:04 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-03-23 23:00:04 +0100
commit57323fa71effad75d78b36a45d5457b1bd782963 (patch)
tree50d7a5bacacebcdf59d5bf38dff84c83bf557d31 /src
parent14feea7ab84df3e367bc3732e8ba1470e1a3f5a7 (diff)
downloadweechat-57323fa71effad75d78b36a45d5457b1bd782963.zip
Removed sizeof(char) and useless type casts from void* to another pointer type (patch from Leonid Evdokimov)
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c4
-rw-r--r--src/core/wee-config-file.c13
-rw-r--r--src/core/wee-hook.c32
-rw-r--r--src/core/wee-input.c4
-rw-r--r--src/core/wee-list.c5
-rw-r--r--src/core/wee-log.c5
-rw-r--r--src/core/wee-string.c21
-rw-r--r--src/core/wee-upgrade.c2
-rw-r--r--src/core/wee-utf8.c2
-rw-r--r--src/core/wee-util.c6
-rw-r--r--src/core/weechat.c3
-rw-r--r--src/gui/curses/gui-curses-bar.c2
-rw-r--r--src/gui/curses/gui-curses-color.c8
-rw-r--r--src/gui/curses/gui-curses-window.c2
-rw-r--r--src/gui/gtk/gui-gtk-window.c2
-rw-r--r--src/gui/gui-action.c2
-rw-r--r--src/gui/gui-bar-item.c4
-rw-r--r--src/gui/gui-bar.c2
-rw-r--r--src/gui/gui-buffer.c8
-rw-r--r--src/gui/gui-chat.c2
-rw-r--r--src/gui/gui-color.c2
-rw-r--r--src/gui/gui-completion.c8
-rw-r--r--src/gui/gui-filter.c6
-rw-r--r--src/gui/gui-history.c4
-rw-r--r--src/gui/gui-hotlist.c4
-rw-r--r--src/gui/gui-infobar.c2
-rw-r--r--src/gui/gui-input.c6
-rw-r--r--src/gui/gui-keyboard.c10
-rw-r--r--src/gui/gui-nicklist.c4
-rw-r--r--src/gui/gui-window.c8
-rw-r--r--src/plugins/alias/alias.c12
-rw-r--r--src/plugins/aspell/aspell.c18
-rw-r--r--src/plugins/charset/charset.c6
-rw-r--r--src/plugins/fifo/fifo.c7
-rw-r--r--src/plugins/irc/irc-channel.c4
-rw-r--r--src/plugins/irc/irc-color.c6
-rw-r--r--src/plugins/irc/irc-command.c6
-rw-r--r--src/plugins/irc/irc-completion.c2
-rw-r--r--src/plugins/irc/irc-dcc.c17
-rw-r--r--src/plugins/irc/irc-mode.c9
-rw-r--r--src/plugins/irc/irc-nick.c2
-rw-r--r--src/plugins/irc/irc-protocol.c4
-rw-r--r--src/plugins/irc/irc-server.c27
-rw-r--r--src/plugins/logger/logger-buffer.c2
-rw-r--r--src/plugins/logger/logger-tail.c11
-rw-r--r--src/plugins/logger/logger.c2
-rw-r--r--src/plugins/plugin-api.c3
-rw-r--r--src/plugins/plugin-config.c8
-rw-r--r--src/plugins/plugin-infolist.c14
-rw-r--r--src/plugins/plugin.c4
-rw-r--r--src/plugins/scripts/lua/weechat-lua.c2
-rw-r--r--src/plugins/scripts/perl/weechat-perl.c58
-rw-r--r--src/plugins/scripts/python/weechat-python.c83
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby.c2
-rw-r--r--src/plugins/scripts/script-api.c8
-rw-r--r--src/plugins/scripts/script-callback.c2
-rw-r--r--src/plugins/scripts/script.c22
-rw-r--r--src/plugins/trigger/trigger-libc.c20
-rw-r--r--src/plugins/trigger/trigger-libirc.c2
-rw-r--r--src/plugins/trigger/trigger.c4
60 files changed, 269 insertions, 281 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index f7a7108d4..5948720b5 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -526,7 +526,7 @@ command_builtin (void *data, struct t_gui_buffer *buffer,
else
{
length = strlen (argv_eol[1]) + 2;
- command = (char *)malloc (length * sizeof (char));
+ command = malloc (length);
if (command)
{
snprintf (command, length, "/%s", argv_eol[1]);
@@ -1950,7 +1950,7 @@ command_upgrade (void *data, struct t_gui_buffer *buffer,
}
filename_length = strlen (weechat_home) + strlen (WEECHAT_SESSION_NAME) + 2;
- filename = (char *)malloc (filename_length * sizeof (char));
+ filename = malloc (filename_length);
if (!filename)
return -2;
snprintf (filename, filename_length, "%s%s" WEECHAT_SESSION_NAME,
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 2a932b2bf..5b5c7c2e4 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -86,7 +86,7 @@ config_file_new (struct t_weechat_plugin *plugin, char *filename,
if (config_file_search (filename))
return NULL;
- new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file));
+ new_config_file = malloc (sizeof (*new_config_file));
if (new_config_file)
{
new_config_file->plugin = plugin;
@@ -157,7 +157,7 @@ config_file_new_section (struct t_config_file *config_file, char *name,
if (!config_file || !name)
return NULL;
- new_section = (struct t_config_section *)malloc (sizeof (struct t_config_section));
+ new_section = malloc (sizeof (*new_section));
if (new_section)
{
new_section->name = strdup (name);
@@ -275,7 +275,7 @@ config_file_new_option (struct t_config_file *config_file,
return NULL;
}
- new_option = (struct t_config_option *)malloc (sizeof (struct t_config_option));
+ new_option = malloc (sizeof (*new_option));
if (new_option)
{
new_option->name = strdup (name);
@@ -849,8 +849,7 @@ config_file_write_internal (struct t_config_file *config_file,
/* build filename */
filename_length = strlen (weechat_home) +
strlen (config_file->filename) + 2;
- filename =
- (char *)malloc (filename_length * sizeof (char));
+ filename = malloc (filename_length);
if (!filename)
return -2;
snprintf (filename, filename_length, "%s%s%s",
@@ -858,7 +857,7 @@ config_file_write_internal (struct t_config_file *config_file,
/* build temporary filename, this temp file will be renamed to filename
after write */
- filename2 = (char *)malloc ((filename_length + 32) * sizeof (char));
+ filename2 = malloc (filename_length + 32);
if (!filename2)
{
free (filename);
@@ -972,7 +971,7 @@ config_file_read (struct t_config_file *config_file)
/* build filename */
filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2;
- filename = (char *)malloc (filename_length * sizeof (char));
+ filename = malloc (filename_length);
if (!filename)
return -2;
snprintf (filename, filename_length, "%s%s%s",
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 4816ff2fc..ba579decb 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -330,10 +330,10 @@ hook_command (struct t_weechat_plugin *plugin, char *command, char *description,
}
}
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_command = (struct t_hook_command *)malloc (sizeof (struct t_hook_command));
+ new_hook_command = malloc (sizeof (*new_hook_command));
if (!new_hook_command)
{
free (new_hook);
@@ -441,10 +441,10 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second,
struct t_hook_timer *new_hook_timer;
struct timezone tz;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_timer = (struct t_hook_timer *)malloc (sizeof (struct t_hook_timer));
+ new_hook_timer = malloc (sizeof (*new_hook_timer));
if (!new_hook_timer)
{
free (new_hook);
@@ -623,10 +623,10 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
if ((fd < 0) || hook_search_fd (fd))
return NULL;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_fd = (struct t_hook_fd *)malloc (sizeof (struct t_hook_fd));
+ new_hook_fd = malloc (sizeof (*new_hook_fd));
if (!new_hook_fd)
{
free (new_hook);
@@ -740,10 +740,10 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer,
struct t_hook *new_hook;
struct t_hook_print *new_hook_print;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_print = (struct t_hook_print *)malloc (sizeof (struct t_hook_print));
+ new_hook_print = malloc (sizeof (*new_hook_print));
if (!new_hook_print)
{
free (new_hook);
@@ -883,10 +883,10 @@ hook_signal (struct t_weechat_plugin *plugin, char *signal,
if (!signal || !signal[0])
return NULL;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_signal = (struct t_hook_signal *)malloc (sizeof (struct t_hook_signal));
+ new_hook_signal = malloc (sizeof (*new_hook_signal));
if (!new_hook_signal)
{
free (new_hook);
@@ -947,10 +947,10 @@ hook_config (struct t_weechat_plugin *plugin, char *type, char *option,
struct t_hook *new_hook;
struct t_hook_config *new_hook_config;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_config = (struct t_hook_config *)malloc (sizeof (struct t_hook_config));
+ new_hook_config = malloc (sizeof (*new_hook_config));
if (!new_hook_config)
{
free (new_hook);
@@ -1020,10 +1020,10 @@ hook_completion (struct t_weechat_plugin *plugin, char *completion,
if (!completion || !completion[0] || strchr (completion, ' '))
return NULL;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_completion = (struct t_hook_completion *)malloc (sizeof (struct t_hook_completion));
+ new_hook_completion = malloc (sizeof (*new_hook_completion));
if (!new_hook_completion)
{
free (new_hook);
@@ -1092,10 +1092,10 @@ hook_modifier (struct t_weechat_plugin *plugin, char *modifier,
if (!modifier || !modifier[0])
return NULL;
- new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
- new_hook_modifier = (struct t_hook_modifier *)malloc (sizeof (struct t_hook_modifier));
+ new_hook_modifier = malloc (sizeof (*new_hook_modifier));
if (!new_hook_modifier)
{
free (new_hook);
diff --git a/src/core/wee-input.c b/src/core/wee-input.c
index e0f18cf3a..4f22b759e 100644
--- a/src/core/wee-input.c
+++ b/src/core/wee-input.c
@@ -122,9 +122,9 @@ input_exec_command (struct t_gui_buffer *buffer, char *string,
/*if (cfg_irc_send_unknown_commands)
{
if (ptr_args)
- unknown_command = (char *)malloc ((strlen (command + 1) + 1 + strlen (ptr_args) + 1) * sizeof (char));
+ unknown_command = malloc (strlen (command + 1) + 1 + strlen (ptr_args) + 1);
else
- unknown_command = (char *)malloc ((strlen (command + 1) + 1) * sizeof (char));
+ unknown_command = malloc (strlen (command + 1) + 1);
if (unknown_command)
{
diff --git a/src/core/wee-list.c b/src/core/wee-list.c
index 70ed465de..ac1e595ab 100644
--- a/src/core/wee-list.c
+++ b/src/core/wee-list.c
@@ -42,7 +42,7 @@ weelist_new ()
{
struct t_weelist *new_weelist;
- new_weelist = (struct t_weelist *)malloc (sizeof (struct t_weelist));
+ new_weelist = malloc (sizeof (*new_weelist));
if (new_weelist)
{
new_weelist->items = NULL;
@@ -146,7 +146,8 @@ weelist_add (struct t_weelist *weelist, char *data, char *where)
if (!weelist || !data || !data[0] || !where || !where[0])
return NULL;
- if ((new_item = ((struct t_weelist_item *)malloc (sizeof (struct t_weelist_item)))))
+ new_item = malloc (sizeof (*new_item));
+ if (new_item)
{
new_item->data = strdup (data);
weelist_insert (weelist, new_item, where);
diff --git a/src/core/wee-log.c b/src/core/wee-log.c
index e7229797e..65027ca40 100644
--- a/src/core/wee-log.c
+++ b/src/core/wee-log.c
@@ -63,8 +63,7 @@ log_open (char *filename, char *mode)
else
{
filename_length = strlen (weechat_home) + 64;
- weechat_log_filename =
- (char *)malloc (filename_length * sizeof (char));
+ weechat_log_filename = malloc (filename_length);
snprintf (weechat_log_filename, filename_length,
"%s/%s", weechat_home, WEECHAT_LOG_NAME);
}
@@ -204,7 +203,7 @@ log_crash_rename ()
log_close ();
length = strlen (weechat_home) + 128;
- new_name = (char *)malloc (length * sizeof (char));
+ new_name = malloc (length);
if (new_name)
{
time_now = time (NULL);
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 3fc7f9866..1c6a33669 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -59,7 +59,7 @@ string_strndup (char *string, int length)
if ((int)strlen (string) < length)
return strdup (string);
- result = (char *)malloc ((length + 1) * sizeof (char));
+ result = malloc (length + 1);
if (!result)
return NULL;
@@ -361,7 +361,7 @@ string_replace (char *string, char *search, char *replace)
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
/* allocate new string */
- new_string = (char *)malloc (length_new * sizeof (char));
+ new_string = malloc (length_new);
if (!new_string)
return strdup (string);
@@ -478,7 +478,7 @@ string_convert_hex_chars (char *string)
int pos_output;
long number;
- output = (char *)malloc ((strlen (string) + 1) * sizeof (char));
+ output = malloc (strlen (string) + 1);
if (output)
{
pos_output = 0;
@@ -587,7 +587,7 @@ string_explode (char *string, char *separators, int keep_eol,
if ((num_items_max != 0) && (n_items > num_items_max))
n_items = num_items_max;
- array = (char **)malloc ((n_items + 1) * sizeof (char *));
+ array = malloc ((n_items + 1) * sizeof (array[0]));
ptr1 = string2;
ptr2 = string2;
@@ -632,8 +632,7 @@ string_explode (char *string, char *separators, int keep_eol,
}
else
{
- array[i] =
- (char *)malloc ((ptr2 - ptr1 + 1) * sizeof (char));
+ array[i] = malloc (ptr2 - ptr1 + 1);
strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
}
@@ -694,7 +693,7 @@ string_build_with_exploded (char **exploded_string, char *separator)
length += strlen (exploded_string[i]) + length_separator;
}
- result = (char *)malloc ((length + 1) * sizeof (char));
+ result = malloc (length + 1);
result[0] = '\0';
for (i = 0; exploded_string[i]; i++)
@@ -733,11 +732,11 @@ string_split_command (char *command, char separator)
ptr = ++p;
}
- array = (char **)malloc ((nb_substr + 1) * sizeof (char *));
+ array = malloc ((nb_substr + 1) * sizeof (array[0]));
if (!array)
return NULL;
- buffer = (char *)malloc ((strlen(command) + 1) * sizeof (char));
+ buffer = malloc (strlen(command) + 1);
if (!buffer)
{
free (array);
@@ -787,7 +786,7 @@ string_split_command (char *command, char separator)
free (buffer);
- array = (char **)realloc (array, (arr_idx + 1) * sizeof(char *));
+ array = realloc (array, (arr_idx + 1) * sizeof(array[0]));
return array;
}
@@ -838,7 +837,7 @@ string_iconv (int from_utf8, char *from_code, char *to_code, char *string)
ptr_inbuf = inbuf;
inbytesleft = strlen (inbuf);
outbytesleft = inbytesleft * 4;
- outbuf = (char *)malloc ((outbytesleft + 2) * sizeof (char));
+ outbuf = malloc (outbytesleft + 2);
ptr_outbuf = outbuf;
ptr_inbuf_shift = NULL;
done = 0;
diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c
index 4f9419860..f1b5380b0 100644
--- a/src/core/wee-upgrade.c
+++ b/src/core/wee-upgrade.c
@@ -600,7 +600,7 @@ session_read_str (FILE *file, char **string)
if (string)
{
- (*string) = (char *)malloc ((length + 1) * sizeof (char));
+ (*string) = malloc (length + 1);
if (!(*string))
return 0;
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c
index f02238a1e..c6f6f5a4d 100644
--- a/src/core/wee-utf8.c
+++ b/src/core/wee-utf8.c
@@ -300,7 +300,7 @@ utf8_strlen_screen (char *string)
return utf8_strlen (string);
num_char = mbstowcs (NULL, string, 0) + 1;
- wstring = (wchar_t *)malloc ((num_char + 1) * sizeof (wchar_t));
+ wstring = malloc ((num_char + 1) * sizeof (wstring[0]));
if (!wstring)
return utf8_strlen (string);
diff --git a/src/core/wee-util.c b/src/core/wee-util.c
index cd81a94e2..c96718ff8 100644
--- a/src/core/wee-util.c
+++ b/src/core/wee-util.c
@@ -222,7 +222,7 @@ util_search_full_lib_name (char *filename, char *sys_directory)
if (CONFIG_STRING(config_plugins_extension)
&& CONFIG_STRING(config_plugins_extension)[0])
length += strlen (CONFIG_STRING(config_plugins_extension));
- name_with_ext = (char *)malloc (length * sizeof (char));
+ name_with_ext = malloc (length);
if (!name_with_ext)
return strdup (filename);
strcpy (name_with_ext, filename);
@@ -234,7 +234,7 @@ util_search_full_lib_name (char *filename, char *sys_directory)
/* try WeeChat user's dir */
length = strlen (weechat_home) + strlen (name_with_ext) +
strlen (sys_directory) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (!final_name)
{
free (name_with_ext);
@@ -252,7 +252,7 @@ util_search_full_lib_name (char *filename, char *sys_directory)
/* try WeeChat global lib dir */
length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) +
strlen (sys_directory) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (!final_name)
{
free (name_with_ext);
diff --git a/src/core/weechat.c b/src/core/weechat.c
index 3f192968d..92cd724b8 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -357,8 +357,7 @@ weechat_create_home_dirs ()
weechat_shutdown (EXIT_FAILURE, 0);
}
dir_length = strlen (ptr_home) + 10;
- weechat_home =
- (char *)malloc (dir_length * sizeof (char));
+ weechat_home = malloc (dir_length);
if (!weechat_home)
{
string_iconv_fprintf (stderr,
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index bf167b092..eddfb3704 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -158,7 +158,7 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
if (!gui_init_ok)
return 0;
- new_bar_window = (struct t_gui_bar_window *) malloc (sizeof (struct t_gui_bar_window));
+ new_bar_window = malloc (sizeof (*new_bar_window));
if (new_bar_window)
{
new_bar_window->bar = bar;
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c
index 1adb758ee..6d0fa729f 100644
--- a/src/gui/curses/gui-curses-color.c
+++ b/src/gui/curses/gui-curses-color.c
@@ -159,7 +159,7 @@ gui_color_assign (t_gui_color **color, char *fg_and_bg)
if (!(*color))
{
- *color = (t_gui_color *)malloc (sizeof (t_gui_color));
+ *color = malloc (sizeof (**color));
if (!(*color))
return;
*color->foreground = 0;
@@ -228,7 +228,7 @@ gui_color_assign (t_gui_color **color, char *fg_and_bg)
if (*color->string)
free (*color->string);
- *color->string = (char *)malloc (4 * sizeof (char));
+ *color->string = malloc (4);
if (*color->string)
snprintf (*color->string, 4,
"%s%02d",
@@ -271,14 +271,14 @@ gui_color_build (int number, int foreground, int background)
{
struct t_gui_color *new_color;
- new_color = (struct t_gui_color *)malloc (sizeof (struct t_gui_color));
+ new_color = malloc (sizeof (*new_color));
if (!new_color)
return NULL;
new_color->foreground = gui_weechat_colors[foreground].foreground;
new_color->background = gui_weechat_colors[background].foreground;
new_color->attributes = gui_weechat_colors[foreground].attributes;
- new_color->string = (char *)malloc (4 * sizeof (char));
+ new_color->string = malloc (4);
if (new_color->string)
snprintf (new_color->string, 4,
"%s%02d",
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 550d2a909..f760ba769 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -75,7 +75,7 @@ gui_window_objects_init (struct t_gui_window *window)
{
struct t_gui_curses_objects *new_objects;
- if ((new_objects = (struct t_gui_curses_objects *)malloc (sizeof (struct t_gui_curses_objects))))
+ if ((new_objects = malloc (sizeof (*new_objects))))
{
window->gui_objects = new_objects;
GUI_CURSES(window)->win_title = NULL;
diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c
index 8f22655a8..0c34d1815 100644
--- a/src/gui/gtk/gui-gtk-window.c
+++ b/src/gui/gtk/gui-gtk-window.c
@@ -68,7 +68,7 @@ gui_window_objects_init (struct t_gui_window *window)
{
struct t_gui_gtk_objects *new_objects;
- if ((new_objects = (struct t_gui_gtk_objects *)malloc (sizeof (struct t_gui_gtk_objects))))
+ if ((new_objects = malloc (sizeof (*new_objects))))
{
window->gui_objects = new_objects;
GUI_GTK(window)->textview_chat = NULL;
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index 396de1ffd..ebe07fd0b 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -63,7 +63,7 @@ gui_action_clipboard_copy (char *buffer, int size)
if (gui_input_clipboard != NULL)
free (gui_input_clipboard);
- gui_input_clipboard = (char *)malloc((size + 1) * sizeof(*gui_input_clipboard));
+ gui_input_clipboard = malloc((size + 1) * sizeof(*gui_input_clipboard));
if (gui_input_clipboard)
{
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 5bac05335..c5cce18b8 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -117,7 +117,7 @@ gui_bar_item_new (struct t_weechat_plugin *plugin, char *name,
return NULL;
/* create bar item */
- new_bar_item = (struct t_gui_bar_item *) malloc (sizeof (struct t_gui_bar_item));
+ new_bar_item = malloc (sizeof (*new_bar_item));
if (new_bar_item)
{
new_bar_item->plugin = plugin;
@@ -540,7 +540,7 @@ gui_bar_item_hook (char *signal, char *item)
{
struct t_gui_bar_item_hook *bar_item_hook;
- bar_item_hook = (struct t_gui_bar_item_hook *)malloc (sizeof (struct t_gui_bar_item_hook));
+ bar_item_hook = malloc (sizeof (*bar_item_hook));
if (bar_item_hook)
{
bar_item_hook->hook = hook_signal (NULL, signal,
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index 85f5f3603..d5cec0517 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -137,7 +137,7 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
return NULL;
/* create bar */
- new_bar = (struct t_gui_bar *) malloc (sizeof (struct t_gui_bar));
+ new_bar = malloc (sizeof (*new_bar));
if (new_bar)
{
new_bar->plugin = plugin;
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index c02ef92dc..7433e813f 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -88,7 +88,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
}
/* create new buffer */
- new_buffer = (struct t_gui_buffer *)(malloc (sizeof (struct t_gui_buffer)));
+ new_buffer = malloc (sizeof (*new_buffer));
if (new_buffer)
{
/* init buffer */
@@ -133,8 +133,8 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
new_buffer->input_callback_data = input_callback_data;
new_buffer->input_nick = NULL;
new_buffer->input_buffer_alloc = GUI_BUFFER_INPUT_BLOCK_SIZE;
- new_buffer->input_buffer = (char *)malloc (GUI_BUFFER_INPUT_BLOCK_SIZE * sizeof (char));
- new_buffer->input_buffer_color_mask = (char *)malloc (GUI_BUFFER_INPUT_BLOCK_SIZE * sizeof (char));
+ new_buffer->input_buffer = malloc (GUI_BUFFER_INPUT_BLOCK_SIZE);
+ new_buffer->input_buffer_color_mask = malloc (GUI_BUFFER_INPUT_BLOCK_SIZE);
new_buffer->input_buffer[0] = '\0';
new_buffer->input_buffer_color_mask[0] = '\0';
new_buffer->input_buffer_size = 0;
@@ -144,7 +144,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, char *category, char *name,
new_buffer->input_refresh_needed = 1;
/* init completion */
- new_completion = (struct t_gui_completion *)malloc (sizeof (struct t_gui_completion));
+ new_completion = malloc (sizeof (*new_completion));
if (new_completion)
{
new_buffer->completion = new_completion;
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index b06bee0b7..f08ab36f6 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -603,7 +603,7 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date,
{
struct t_gui_line *new_line, *ptr_line;
- new_line = (struct t_gui_line *)malloc (sizeof (struct t_gui_line));
+ new_line = malloc (sizeof (*new_line));
if (!new_line)
{
log_printf (_("Not enough memory for new line"));
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index c267b1200..631bf6879 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -81,7 +81,7 @@ gui_color_decode (unsigned char *string)
int out_length, out_pos, length;
out_length = (strlen ((char *)string) * 2) + 1;
- out = (unsigned char *)malloc (out_length * sizeof (unsigned char));
+ out = malloc (out_length);
if (!out)
return NULL;
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 7c41879b0..e505838f2 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -179,7 +179,7 @@ gui_completion_strdup_alphanum (char *string)
{
char *result, *pos;
- result = (char *)malloc ((strlen (string) + 1) * sizeof (char));
+ result = malloc (strlen (string) + 1);
pos = result;
while (string[0])
{
@@ -334,7 +334,7 @@ gui_completion_list_add_filename (struct t_gui_completion *completion)
char home[3] = { '~', DIR_SEPARATOR_CHAR, '\0' };
buffer_len = PATH_MAX;
- buffer = (char *)malloc (buffer_len * sizeof (char));
+ buffer = malloc (buffer_len);
if (!buffer)
return;
@@ -971,7 +971,7 @@ gui_completion_find_context (struct t_gui_completion *completion, char *data,
if (pos_start <= pos_end)
{
completion->position_replace = pos_start;
- completion->base_word = (char *)malloc ((pos_end - pos_start + 2) * sizeof (char));
+ completion->base_word = malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_word[i - pos_start] = data[i];
completion->base_word[pos_end - pos_start + 1] = '\0';
@@ -996,7 +996,7 @@ gui_completion_find_context (struct t_gui_completion *completion, char *data,
if (data[pos_end] == ' ')
pos_end--;
- completion->base_command = (char *)malloc ((pos_end - pos_start + 2) * sizeof (char));
+ completion->base_command = malloc (pos_end - pos_start + 2);
for (i = pos_start; i <= pos_end; i++)
completion->base_command[i - pos_start] = data[i];
completion->base_command[pos_end - pos_start + 1] = '\0';
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index b5259a788..fc8c96fe9 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -271,7 +271,7 @@ gui_filter_new (char *buffer, char *tags, char *regex)
if (!regex_prefix)
return NULL;
- regex1 = (regex_t *)malloc (sizeof (regex_t));
+ regex1 = malloc (sizeof (*regex1));
if (regex1)
{
if (regcomp (regex1, regex_prefix,
@@ -283,7 +283,7 @@ gui_filter_new (char *buffer, char *tags, char *regex)
}
}
- regex2 = (regex_t *)malloc (sizeof (regex_t));
+ regex2 = malloc (sizeof (*regex2));
if (regex2)
{
if (regcomp (regex2, pos_regex_message,
@@ -301,7 +301,7 @@ gui_filter_new (char *buffer, char *tags, char *regex)
}
/* create new filter */
- new_filter = (struct t_gui_filter *)(malloc (sizeof (struct t_gui_filter)));
+ new_filter = (malloc (sizeof (*new_filter)));
if (new_filter)
{
/* init filter */
diff --git a/src/gui/gui-history.c b/src/gui/gui-history.c
index d214ec67e..d7b98d47b 100644
--- a/src/gui/gui-history.c
+++ b/src/gui/gui-history.c
@@ -55,7 +55,7 @@ gui_history_buffer_add (struct t_gui_buffer *buffer, char *string)
|| (buffer->history
&& (strcmp (buffer->history->text, string) != 0)))
{
- new_history = (struct t_gui_history *)malloc (sizeof (struct t_gui_history));
+ new_history = malloc (sizeof (*new_history));
if (new_history)
{
new_history->text = strdup (string);
@@ -105,7 +105,7 @@ gui_history_global_add (char *string)
|| (history_global
&& (strcmp (history_global->text, string) != 0)))
{
- new_history = (struct t_gui_history *)malloc (sizeof (struct t_gui_history));
+ new_history = malloc (sizeof (*new_history));
if (new_history)
{
new_history->text = strdup (string);
diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c
index f45be1a93..01fcac6ad 100644
--- a/src/gui/gui-hotlist.c
+++ b/src/gui/gui-hotlist.c
@@ -217,7 +217,7 @@ gui_hotlist_add (struct t_gui_buffer *buffer, int priority,
gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist);
}
- new_hotlist = (struct t_gui_hotlist *)malloc (sizeof (struct t_gui_hotlist));
+ new_hotlist = malloc (sizeof (*new_hotlist));
if (!new_hotlist)
{
log_printf (_("Error: not enough memory to add a buffer to "
@@ -249,7 +249,7 @@ gui_hotlist_dup (struct t_gui_hotlist *hotlist)
{
struct t_gui_hotlist *new_hotlist;
- new_hotlist = (struct t_gui_hotlist *)malloc (sizeof (struct t_gui_hotlist));
+ new_hotlist = malloc (sizeof (*new_hotlist));
if (new_hotlist)
{
new_hotlist->priority = hotlist->priority;
diff --git a/src/gui/gui-infobar.c b/src/gui/gui-infobar.c
index 3e4024619..31bdbd451 100644
--- a/src/gui/gui-infobar.c
+++ b/src/gui/gui-infobar.c
@@ -59,7 +59,7 @@ gui_infobar_printf (int delay, int color, char *message, ...)
vsnprintf (buf, sizeof (buf) - 1, message, argptr);
va_end (argptr);
- ptr_infobar = (struct t_gui_infobar *)malloc (sizeof (struct t_gui_infobar));
+ ptr_infobar = malloc (sizeof (*ptr_infobar));
if (ptr_infobar)
{
buf2 = (char *)gui_color_decode ((unsigned char *)buf);
diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c
index ee834b3fa..3cb5dfa21 100644
--- a/src/gui/gui-input.c
+++ b/src/gui/gui-input.c
@@ -56,9 +56,9 @@ gui_input_optimize_size (struct t_gui_buffer *buffer)
if (buffer->input_buffer_alloc != optimal_size)
{
buffer->input_buffer_alloc = optimal_size;
- buffer->input_buffer = realloc (buffer->input_buffer, optimal_size * sizeof (char));
+ buffer->input_buffer = realloc (buffer->input_buffer, optimal_size);
buffer->input_buffer_color_mask = realloc (buffer->input_buffer_color_mask,
- optimal_size * sizeof (char));
+ optimal_size);
}
}
}
@@ -150,7 +150,7 @@ gui_input_insert_string (struct t_gui_buffer *buffer, char *string, int pos)
buffer->input_buffer_pos += length;
- string2 = (char *)malloc ((size + 2) * sizeof (char));
+ string2 = malloc (size + 2);
if (string2)
{
snprintf (string2, size + 2, "*%s", string);
diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c
index d32acb99e..00b6aeda7 100644
--- a/src/gui/gui-keyboard.c
+++ b/src/gui/gui-keyboard.c
@@ -243,7 +243,7 @@ gui_keyboard_get_internal_code (char *key)
{
char *result;
- if ((result = (char *)malloc ((strlen (key) + 1) * sizeof (char))))
+ if ((result = malloc (strlen (key) + 1)))
{
result[0] = '\0';
while (key[0])
@@ -286,7 +286,7 @@ gui_keyboard_get_expanded_name (char *key)
{
char *result;
- if ((result = (char *)malloc (((strlen (key) * 5) + 1) * sizeof (char))))
+ if ((result = malloc ((strlen (key) * 5) + 1)))
{
result[0] = '\0';
while (key[0])
@@ -390,7 +390,7 @@ gui_keyboard_new (char *key, char *command, t_gui_key_func *function,
char *internal_code;
int length;
- if ((new_key = (struct t_gui_key *)malloc (sizeof (struct t_gui_key))))
+ if ((new_key = malloc (sizeof (*new_key))))
{
internal_code = gui_keyboard_get_internal_code (key);
new_key->key = (internal_code) ? strdup (internal_code) : strdup (key);
@@ -736,7 +736,7 @@ gui_keyboard_buffer_optimize ()
if (gui_keyboard_buffer_alloc != optimal_size)
{
gui_keyboard_buffer_alloc = optimal_size;
- gui_keyboard_buffer = realloc (gui_keyboard_buffer, optimal_size * sizeof (char));
+ gui_keyboard_buffer = realloc (gui_keyboard_buffer, optimal_size);
}
}
@@ -752,7 +752,7 @@ gui_keyboard_buffer_reset ()
{
gui_keyboard_buffer_alloc = GUI_KEYBOARD_BUFFER_BLOCK_SIZE;
gui_keyboard_buffer_size = 0;
- gui_keyboard_buffer = (int *)malloc (gui_keyboard_buffer_alloc);
+ gui_keyboard_buffer = malloc (gui_keyboard_buffer_alloc);
}
else
{
diff --git a/src/gui/gui-nicklist.c b/src/gui/gui-nicklist.c
index 30aa8adb7..8d3f098a8 100644
--- a/src/gui/gui-nicklist.c
+++ b/src/gui/gui-nicklist.c
@@ -157,7 +157,7 @@ gui_nicklist_add_group (struct t_gui_buffer *buffer,
if (!name || gui_nicklist_search_group (buffer, parent_group, name))
return NULL;
- new_group = (struct t_gui_nick_group *)malloc (sizeof (struct t_gui_nick_group));
+ new_group = malloc (sizeof (*new_group));
if (!new_group)
return NULL;
@@ -304,7 +304,7 @@ gui_nicklist_add_nick (struct t_gui_buffer *buffer,
if (!name || gui_nicklist_search_nick (buffer, NULL, name))
return NULL;
- new_nick = (struct t_gui_nick *)malloc (sizeof (struct t_gui_nick));
+ new_nick = malloc (sizeof (*new_nick));
if (!new_nick)
return NULL;
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 85c285d66..1655a37c7 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -64,7 +64,7 @@ struct t_gui_window_tree *gui_windows_tree = NULL; /* windows tree */
int
gui_window_tree_init (struct t_gui_window *window)
{
- gui_windows_tree = (struct t_gui_window_tree *)malloc (sizeof (struct t_gui_window_tree));
+ gui_windows_tree = malloc (sizeof (*gui_windows_tree));
if (!gui_windows_tree)
return 0;
gui_windows_tree->parent_node = NULL;
@@ -137,10 +137,10 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
if (parent)
{
- child1 = (struct t_gui_window_tree *)malloc (sizeof (struct t_gui_window_tree));
+ child1 = malloc (sizeof (*child1));
if (!child1)
return NULL;
- child2 = (struct t_gui_window_tree *)malloc (sizeof (struct t_gui_window_tree));
+ child2 = malloc (sizeof (*child2));
if (!child2)
{
free (child1);
@@ -186,7 +186,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
ptr_leaf = gui_windows_tree;
}
- if ((new_window = (struct t_gui_window *)(malloc (sizeof (struct t_gui_window)))))
+ if ((new_window = (malloc (sizeof (*new_window)))))
{
if (!gui_window_objects_init (new_window))
{
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index 461680f2b..203442cb0 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -78,12 +78,12 @@ alias_add_word (char **alias, int *length, char *word)
if (*alias == NULL)
{
- *alias = (char *)malloc ((length_word + 1) * sizeof (char));
+ *alias = malloc (length_word + 1);
strcpy (*alias, word);
}
else
{
- *alias = realloc (*alias, (strlen (*alias) + length_word + 1) * sizeof (char));
+ *alias = realloc (*alias, strlen (*alias) + length_word + 1);
strcat (*alias, word);
}
*length += length_word;
@@ -218,7 +218,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
weechat_command (buffer, args_replaced);
else
{
- alias_command = (char *)malloc ((1 + strlen(args_replaced) + 1) * sizeof (char));
+ alias_command = malloc (1 + strlen(args_replaced) + 1);
if (alias_command)
{
strcpy (alias_command, "/");
@@ -238,7 +238,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
length1 = strlen (*ptr_cmd);
length2 = strlen (argv_eol[1]);
- alias_command = (char *)malloc ((1 + length1 + 1 + length2 + 1) * sizeof (char));
+ alias_command = malloc (1 + length1 + 1 + length2 + 1);
if (alias_command)
{
if (*ptr_cmd[0] != '/')
@@ -260,7 +260,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
(void) weechat_command(buffer, *ptr_cmd);
else
{
- alias_command = (char *)malloc ((1 + strlen (*ptr_cmd) + 1) * sizeof (char));
+ alias_command = malloc (1 + strlen (*ptr_cmd) + 1);
if (alias_command)
{
strcpy (alias_command, "/");
@@ -306,7 +306,7 @@ alias_new (char *name, char *command)
return ptr_alias;
}
- new_alias = (struct t_alias *)malloc (sizeof (struct t_alias));
+ new_alias = malloc (sizeof (*new_alias));
if (new_alias)
{
new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, NULL,
diff --git a/src/plugins/aspell/aspell.c b/src/plugins/aspell/aspell.c
index 4d0c22b79..dd302895f 100644
--- a/src/plugins/aspell/aspell.c
+++ b/src/plugins/aspell/aspell.c
@@ -53,7 +53,7 @@ weechat_aspell_new_speller (void)
{
aspell_speller_t *s;
- s = (aspell_speller_t *)malloc (sizeof (aspell_speller_t));
+ s = malloc (sizeof (*s));
if (!s)
{
weechat_aspell_plugin->print (weechat_aspell_plugin, NULL, NULL,
@@ -208,7 +208,7 @@ weechat_aspell_new_config (void)
{
aspell_config_t *c;
- c = (aspell_config_t *)malloc (sizeof (aspell_config_t));
+ c = malloc (sizeof (*c));
if (!c)
{
weechat_aspell_plugin->print (weechat_aspell_plugin, NULL, NULL,
@@ -833,7 +833,7 @@ weechat_aspell_config_save (void)
if (found == 0)
{
n = strlen (servers) + strlen (p->server) + 2;
- servers = (char *)realloc (servers, n * sizeof (char));
+ servers = realloc (servers, n);
strcat (servers, " ");
strcat (servers, p->server);
weechat_aspell_plugin->set_plugin_config (weechat_aspell_plugin, "servers", servers);
@@ -853,13 +853,13 @@ weechat_aspell_config_save (void)
else
{
n = strlen (channels) + strlen (q->channel) + 2;
- channels = (char *)realloc (channels, n * sizeof (char));
+ channels = realloc (channels, n);
strcat (channels, " ");
strcat (channels, q->channel);
}
n = 7 + strlen (p->server) + strlen (q->channel);
- option = (char *)malloc (n * sizeof (char));
+ option = malloc (n);
snprintf (option, n, "lang_%s_%s", p->server, q->channel);
weechat_aspell_plugin->set_plugin_config (weechat_aspell_plugin, option, q->speller->lang);
free (option);
@@ -869,7 +869,7 @@ weechat_aspell_config_save (void)
if (channels)
{
n = 10 + strlen (p->server);
- option = (char *)malloc (n * sizeof (char));
+ option = malloc (n);
snprintf (option, n, "channels_%s", p->server);
weechat_aspell_plugin->set_plugin_config (weechat_aspell_plugin, option, channels);
free (option);
@@ -904,7 +904,7 @@ weechat_aspell_config_load(void)
for (i=0; i<s; i++)
{
n = 10 + strlen (servers_list[i]);
- option_s = (char *)malloc (n * sizeof (char));
+ option_s = malloc (n);
snprintf (option_s, n, "channels_%s", servers_list[i]);
channels = weechat_aspell_plugin->get_plugin_config (weechat_aspell_plugin, option_s);
@@ -916,7 +916,7 @@ weechat_aspell_config_load(void)
for (j=0; j<c; j++)
{
n = 7 + strlen (servers_list[i]) + strlen (channels_list[j]);
- option_l = (char *)malloc (n * sizeof (char));
+ option_l = malloc (n);
snprintf (option_l, n, "lang_%s_%s", servers_list[i], channels_list[j]);
lang = weechat_aspell_plugin->get_plugin_config (weechat_aspell_plugin, option_l);
@@ -1179,7 +1179,7 @@ weechat_aspell_clean_word (char *word, int *offset)
return NULL;
}
- w = (char *)malloc ((len+1) * sizeof(char));
+ w = malloc (len+1);
if (w) {
memcpy (w, buffer + *offset, len);
diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c
index 78b1e8b08..81e71d6ec 100644
--- a/src/plugins/charset/charset.c
+++ b/src/plugins/charset/charset.c
@@ -110,7 +110,7 @@ charset_new (char *name, char *charset)
return ptr_charset;
}
- new_charset = (struct t_charset *)malloc (sizeof (struct t_charset));
+ new_charset = malloc (sizeof (*new_charset));
{
new_charset->name = strdup (name);
new_charset->charset = strdup (charset);
@@ -486,7 +486,7 @@ charset_get (char *type, char *name)
int length;
length = strlen (type) + 1 + strlen (name) + 1;
- option_name = (char *)malloc (length * sizeof (char));
+ option_name = malloc (length);
if (option_name)
{
snprintf (option_name, length, "%s.%s",
@@ -585,7 +585,7 @@ charset_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
&& (weechat_strncasecmp (argv[1], "encode.", 7) != 0))
{
length = strlen (argv[1]) + strlen ("decode.") + 1;
- option_name = (char *)malloc (length * sizeof (char));
+ option_name = malloc (length);
if (option_name)
{
rc = 1;
diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c
index 6bd2e40f0..b79692c15 100644
--- a/src/plugins/fifo/fifo.c
+++ b/src/plugins/fifo/fifo.c
@@ -78,8 +78,7 @@ fifo_create ()
if (!fifo_filename)
{
filename_length = strlen (weechat_home) + 64;
- fifo_filename = (char *)malloc (filename_length *
- sizeof (char));
+ fifo_filename = malloc (filename_length);
snprintf (fifo_filename, filename_length,
"%s/weechat_fifo_%d",
weechat_home, (int) getpid());
@@ -240,8 +239,8 @@ fifo_read ()
ptr_buf = buffer;
if (fifo_unterminated)
{
- buf2 = (char *)malloc ((strlen (fifo_unterminated) +
- strlen (buffer) + 1) * sizeof (char));
+ buf2 = malloc (strlen (fifo_unterminated) +
+ strlen (buffer) + 1);
if (buf2)
{
strcpy (buf2, fifo_unterminated);
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index 72f28b47d..a838786a8 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -47,7 +47,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
struct t_gui_buffer *new_buffer;
/* alloc memory for new channel */
- if ((new_channel = (struct t_irc_channel *)malloc (sizeof (struct t_irc_channel))) == NULL)
+ if ((new_channel = malloc (sizeof (*new_channel))) == NULL)
{
weechat_printf (NULL,
_("%s%s: cannot allocate new channel"),
@@ -411,7 +411,7 @@ irc_channel_get_notify_level (struct t_irc_server *server,
&& (server_default_notify == 1))
server_default_notify = 2;
- name = (char *)malloc ((strlen (channel->name) + 2) * sizeof (char));
+ name = malloc (strlen (channel->name) + 2);
strcpy (name, channel->name);
strcat (name, ":");
pos = strstr (server->notify_levels, name);
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index e64fff19f..d986c0bd7 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -52,7 +52,7 @@ irc_color_decode (unsigned char *string, int keep_irc_colors,
return NULL;
/*out_length = (strlen ((char *)string) * 2) + 1;
- out = (unsigned char *)malloc (out_length * sizeof (unsigned char));
+ out = malloc (out_length);
if (!out)
return NULL;
@@ -209,7 +209,7 @@ irc_color_decode_for_user_entry (unsigned char *string)
return NULL;
/*out_length = (strlen ((char *)string) * 2) + 1;
- out = (unsigned char *)malloc (out_length * sizeof (unsigned char));
+ out = malloc (out_length);
if (!out)
return NULL;
@@ -278,7 +278,7 @@ irc_color_encode (unsigned char *string, int keep_colors)
return NULL;
/*out_length = (strlen ((char *)string) * 2) + 1;
- out = (unsigned char *)malloc (out_length * sizeof (unsigned char));
+ out = malloc (out_length);
if (!out)
return NULL;
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index d246d4dfe..437714cdf 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -119,7 +119,7 @@ irc_command_mode_nicks (struct t_irc_server *server, char *channel,
for (i = 1; i < argc; i++)
length += strlen (argv[i]) + 1;
length += strlen (channel) + (argc * strlen (mode)) + 32;
- command = (char *)malloc (length * sizeof (char));
+ command = malloc (length);
if (command)
{
snprintf (command, length, "MODE %s %s", channel, set);
@@ -258,7 +258,7 @@ irc_command_away_server (struct t_irc_server *server, char *arguments)
{
if (server->away_message)
free (server->away_message);
- server->away_message = (char *)malloc ((strlen (arguments) + 1) * sizeof (char));
+ server->away_message = malloc (strlen (arguments) + 1);
if (server->away_message)
strcpy (server->away_message, arguments);
@@ -1566,7 +1566,7 @@ irc_command_list (void *data, struct t_gui_buffer *buffer, int argc,
if (argc > 1)
{
- ptr_server->cmd_list_regexp = (regex_t *)malloc (sizeof (regex_t));
+ ptr_server->cmd_list_regexp = malloc (sizeof (*ptr_server->cmd_list_regexp));
if (ptr_server->cmd_list_regexp)
{
if ((ret = regcomp (ptr_server->cmd_list_regexp,
diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c
index 5d5d6929e..4089c3fb5 100644
--- a/src/plugins/irc/irc-completion.c
+++ b/src/plugins/irc/irc-completion.c
@@ -232,7 +232,7 @@ irc_completion_channel_nicks_hosts_cb (void *data, char *completion,
{
length = strlen (ptr_nick->name) + 1 +
strlen (ptr_nick->host) + 1;
- buf = (char *)malloc (length * sizeof (char));
+ buf = malloc (length);
if (buf)
{
snprintf (buf, length, "%s!%s",
diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c
index 3539326b0..4ca82b0bb 100644
--- a/src/plugins/irc/irc-dcc.c
+++ b/src/plugins/irc/irc-dcc.c
@@ -169,9 +169,9 @@ irc_dcc_find_filename (struct t_irc_dcc *ptr_dcc)
return;
}
- ptr_dcc->local_filename = (char *)malloc ((strlen (dir2) +
- strlen (ptr_dcc->nick) +
- strlen (ptr_dcc->filename) + 4) * sizeof (char));
+ ptr_dcc->local_filename = malloc (strlen (dir2) +
+ strlen (ptr_dcc->nick) +
+ strlen (ptr_dcc->filename) + 4);
if (!ptr_dcc->local_filename)
return;
@@ -203,7 +203,7 @@ irc_dcc_find_filename (struct t_irc_dcc *ptr_dcc)
return;
}
- filename2 = (char *)malloc ((strlen (ptr_dcc->local_filename) + 16) * sizeof (char));
+ filename2 = malloc (strlen (ptr_dcc->local_filename) + 16);
if (!filename2)
{
irc_dcc_close (ptr_dcc, IRC_DCC_FAILED);
@@ -722,7 +722,7 @@ irc_dcc_alloc ()
struct t_irc_dcc *new_dcc;
/* create new DCC struct */
- if ((new_dcc = (struct t_irc_dcc *)malloc (sizeof (struct t_irc_dcc))) == NULL)
+ if ((new_dcc = malloc (sizeof (*new_dcc))) == NULL)
return NULL;
/* default values */
@@ -979,8 +979,7 @@ irc_dcc_send_request (struct t_irc_server *server, int type, char *nick,
free (dir1);
return;
}
- filename2 = (char *)malloc ((strlen (dir2) +
- strlen (filename) + 4) * sizeof (char));
+ filename2 = malloc (strlen (dir2) + strlen (filename) + 4);
if (!filename2)
{
gui_chat_printf_error (server->buffer,
@@ -1258,8 +1257,8 @@ irc_dcc_chat_recv (struct t_irc_dcc *dcc)
ptr_buf = buffer;
if (dcc->unterminated_message)
{
- buf2 = (char *)malloc ((strlen (dcc->unterminated_message) +
- strlen (buffer) + 1) * sizeof (char));
+ buf2 = malloc (strlen (dcc->unterminated_message) +
+ strlen (buffer) + 1);
if (buf2)
{
strcpy (buf2, dcc->unterminated_message);
diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c
index 6eb280d09..9fd51b2d6 100644
--- a/src/plugins/irc/irc-mode.c
+++ b/src/plugins/irc/irc-mode.c
@@ -224,8 +224,8 @@ irc_mode_user_add (struct t_irc_server *server, char mode)
{
if (!strchr (server->nick_modes, mode))
{
- server->nick_modes = (char *)realloc (server->nick_modes,
- (strlen (server->nick_modes) + 1 + 1) * sizeof (char));
+ server->nick_modes = realloc (server->nick_modes,
+ strlen (server->nick_modes) + 1 + 1);
strcat (server->nick_modes, str_mode);
//gui_status_draw (gui_current_window->buffer, 1);
//gui_input_draw (gui_current_window->buffer, 1);
@@ -233,7 +233,7 @@ irc_mode_user_add (struct t_irc_server *server, char mode)
}
else
{
- server->nick_modes = (char *)malloc (2 * sizeof (char));
+ server->nick_modes = malloc (2);
strcpy (server->nick_modes, str_mode);
//gui_status_draw (gui_current_window->buffer, 1);
//gui_input_draw (gui_current_window->buffer, 1);
@@ -257,8 +257,7 @@ irc_mode_user_remove (struct t_irc_server *server, char mode)
{
new_size = strlen (server->nick_modes);
memmove (pos, pos + 1, strlen (pos + 1) + 1);
- server->nick_modes = (char *)realloc (server->nick_modes,
- new_size * sizeof (char));
+ server->nick_modes = realloc (server->nick_modes, new_size);
//gui_status_draw (gui_current_window->buffer, 1);
//gui_input_draw (gui_current_window->buffer, 1);
}
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c
index 5a5015f53..0ead9034d 100644
--- a/src/plugins/irc/irc-nick.c
+++ b/src/plugins/irc/irc-nick.c
@@ -175,7 +175,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
}
/* alloc memory for new nick */
- if ((new_nick = (struct t_irc_nick *)malloc (sizeof (struct t_irc_nick))) == NULL)
+ if ((new_nick = malloc (sizeof (*new_nick))) == NULL)
return NULL;
/* initialize new nick */
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 04eb67f30..fc8480666 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -1162,7 +1162,7 @@ irc_protocol_cmd_part (struct t_irc_server *server, char *command,
{
join_length = strlen (ptr_channel->name) + 1 +
strlen (ptr_channel->key) + 1;
- join_string = (char *)malloc (join_length * sizeof (char));
+ join_string = malloc (join_length);
if (join_string)
{
snprintf (join_string, join_length, "%s %s",
@@ -3826,7 +3826,7 @@ irc_protocol_cmd_352 (struct t_irc_server *server, char *command,
if (ptr_nick->host)
free (ptr_nick->host);
length = strlen (argv[4]) + 1 + strlen (argv[5]) + 1;
- ptr_nick->host = (char *)malloc (length * sizeof (char));
+ ptr_nick->host = malloc (length);
if (ptr_nick->host)
snprintf (ptr_nick->host, length, "%s@%s", argv[4], argv[5]);
if (pos_attr)
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 8da38c7c5..f7df652b0 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -239,7 +239,7 @@ irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
server->autojoin = strdup (pos_channel);
else
{
- server->autojoin = (char *)malloc ((strlen (pos_channel) + 2) * sizeof (char));
+ server->autojoin = malloc (strlen (pos_channel) + 2);
strcpy (server->autojoin, "#");
strcat (server->autojoin, pos_channel);
}
@@ -253,10 +253,10 @@ irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
// some default values
if (server->port < 0)
server->port = IRC_SERVER_DEFAULT_PORT;
- server->nick2 = (char *)malloc ((strlen (server->nick1) + 2) * sizeof (char));
+ server->nick2 = malloc (strlen (server->nick1) + 2);
strcpy (server->nick2, server->nick1);
server->nick2 = strcat (server->nick2, "1");
- server->nick3 = (char *)malloc ((strlen (server->nick1) + 2) * sizeof (char));
+ server->nick3 = malloc (strlen (server->nick1) + 2);
strcpy (server->nick3, server->nick1);
server->nick3 = strcat (server->nick3, "2");
@@ -300,8 +300,7 @@ irc_server_set_addresses (struct t_irc_server *server, char *addresses)
server->addresses_array = weechat_string_explode (server->addresses,
",", 0, 0,
&server->addresses_count);
- server->ports_array = (int *)malloc (server->addresses_count *
- sizeof (int *));
+ server->ports_array = malloc (server->addresses_count * sizeof (server->ports_array[0]));
for (i = 0; i < server->addresses_count; i++)
{
pos = strchr (server->addresses_array[i], '/');
@@ -572,7 +571,7 @@ irc_server_alloc ()
struct t_irc_server *new_server;
/* alloc memory for new server */
- if ((new_server = (struct t_irc_server *)malloc (sizeof (struct t_irc_server))) == NULL)
+ if ((new_server = malloc (sizeof (*new_server))) == NULL)
{
weechat_printf (NULL,
_("%s%s: error when allocating new server"),
@@ -606,7 +605,7 @@ irc_server_outqueue_add (struct t_irc_server *server, char *msg1, char *msg2,
{
struct t_irc_outqueue *new_outqueue;
- new_outqueue = (struct t_irc_outqueue *)malloc (sizeof (struct t_irc_outqueue));
+ new_outqueue = malloc (sizeof (*new_outqueue));
if (new_outqueue)
{
new_outqueue->message_before_mod = (msg1) ? strdup (msg1) : NULL;
@@ -1288,7 +1287,7 @@ irc_server_msgq_add_msg (struct t_irc_server *server, char *msg)
if (!server->unterminated_message && !msg[0])
return;
- message = (struct t_irc_message *)malloc (sizeof (struct t_irc_message));
+ message = malloc (sizeof (*message));
if (!message)
{
weechat_printf (server->buffer,
@@ -1300,8 +1299,8 @@ irc_server_msgq_add_msg (struct t_irc_server *server, char *msg)
message->server = server;
if (server->unterminated_message)
{
- message->data = (char *)malloc ((strlen (server->unterminated_message) +
- strlen (msg) + 1) * sizeof (char));
+ message->data = malloc (strlen (server->unterminated_message) +
+ strlen (msg) + 1);
if (!message->data)
{
weechat_printf (server->buffer,
@@ -1346,9 +1345,9 @@ irc_server_msgq_add_unterminated (struct t_irc_server *server, char *string)
if (server->unterminated_message)
{
server->unterminated_message =
- (char *)realloc (server->unterminated_message,
- (strlen (server->unterminated_message) +
- strlen (string) + 1) * sizeof (char));
+ realloc (server->unterminated_message,
+ (strlen (server->unterminated_message) +
+ strlen (string) + 1));
if (!server->unterminated_message)
{
weechat_printf (server->buffer,
@@ -2210,7 +2209,7 @@ irc_server_pass_socks5proxy (int sock, char *address, int port)
/* authentication successful then giving address/port to connect */
addr_len = strlen(address);
addr_buffer_len = 4 + 1 + addr_len + 2;
- addr_buffer = (unsigned char *)malloc (addr_buffer_len * sizeof(*addr_buffer));
+ addr_buffer = malloc (addr_buffer_len * sizeof(*addr_buffer));
if (!addr_buffer)
return 1;
addr_buffer[0] = 5; /* version 5 */
diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c
index 13dc5ec39..7db26859c 100644
--- a/src/plugins/logger/logger-buffer.c
+++ b/src/plugins/logger/logger-buffer.c
@@ -46,7 +46,7 @@ logger_buffer_add (struct t_gui_buffer *buffer, char *log_filename)
if (!buffer || !log_filename)
return NULL;
- new_logger_buffer = (struct t_logger_buffer *)malloc (sizeof (struct t_logger_buffer));
+ new_logger_buffer = malloc (sizeof (*new_logger_buffer));
if (new_logger_buffer)
{
new_logger_buffer->buffer = buffer;
diff --git a/src/plugins/logger/logger-tail.c b/src/plugins/logger/logger-tail.c
index 4ed48dfd6..52157a289 100644
--- a/src/plugins/logger/logger-tail.c
+++ b/src/plugins/logger/logger-tail.c
@@ -122,7 +122,7 @@ logger_tail_file (char *filename, int n_lines)
pos_eol[0] = '\0';
pos_eol++;
}
- new_line = (struct t_logger_line *)malloc (sizeof (struct t_logger_line));
+ new_line = malloc (sizeof (*new_line));
if (!new_line)
{
logger_tail_free (ptr_line);
@@ -131,8 +131,8 @@ logger_tail_file (char *filename, int n_lines)
}
if (part_of_line)
{
- new_line->data = (char *)malloc ((strlen (pos_eol) +
- strlen (part_of_line) + 1) * sizeof (char));
+ new_line->data = malloc ((strlen (pos_eol) +
+ strlen (part_of_line) + 1));
if (!new_line->data)
{
free (part_of_line);
@@ -161,8 +161,7 @@ logger_tail_file (char *filename, int n_lines)
add string to part_of_line, we'll use that later */
if (part_of_line)
{
- new_part_of_line = (char *)malloc ((strlen (buf) +
- strlen (part_of_line) + 1) * sizeof (char));
+ new_part_of_line = malloc (strlen (buf) + strlen (part_of_line) + 1);
if (!new_part_of_line)
{
free (part_of_line);
@@ -177,7 +176,7 @@ logger_tail_file (char *filename, int n_lines)
}
else
{
- part_of_line = (char *)malloc ((strlen (buf) + 1) * sizeof (char));
+ part_of_line = malloc (strlen (buf) + 1);
strcpy (part_of_line, buf);
}
ptr_buf = NULL;
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index 7951df9aa..6db3859bb 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -227,7 +227,7 @@ logger_get_filename (struct t_gui_buffer *buffer)
if (name2)
length += strlen (name2);
length += 16;
- res = (char *)malloc (length * sizeof (char));
+ res = malloc (length);
if (res)
{
strcpy (res, log_path2);
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index ffa8a72e2..76b8dee7b 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -99,8 +99,7 @@ plugin_api_mkdir_home (char *directory, int mode)
/* build directory, adding WeeChat home */
dir_length = strlen (weechat_home) + strlen (directory) + 2;
- dir_name =
- (char *)malloc (dir_length * sizeof (char));
+ dir_name = malloc (dir_length);
if (!dir_name)
return 0;
diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c
index e6b1f9186..759c5cefd 100644
--- a/src/plugins/plugin-config.c
+++ b/src/plugins/plugin-config.c
@@ -75,8 +75,7 @@ plugin_config_search (char *plugin_name, char *option_name)
char *internal_option;
struct t_config_option *ptr_option;
- internal_option = (char *)malloc ((strlen (plugin_name) +
- strlen (option_name) + 2) * sizeof (char));
+ internal_option = malloc (strlen (plugin_name) + strlen (option_name) + 2);
if (!internal_option)
return NULL;
@@ -154,7 +153,7 @@ plugin_config_set_internal (char *option, char *value)
{
if (value && value[0])
{
- ptr_option = (struct t_config_option *)malloc (sizeof (struct t_config_option));
+ ptr_option = malloc (sizeof (*ptr_option));
if (ptr_option)
{
/* create new option */
@@ -223,8 +222,7 @@ plugin_config_set (char *plugin_name, char *option_name, char *value)
char *internal_option;
int return_code;
- internal_option = (char *)malloc ((strlen (plugin_name) +
- strlen (option_name) + 2) * sizeof (char));
+ internal_option = malloc (strlen (plugin_name) + strlen (option_name) + 2);
if (!internal_option)
return 0;
diff --git a/src/plugins/plugin-infolist.c b/src/plugins/plugin-infolist.c
index 233a9c1d9..689345ecb 100644
--- a/src/plugins/plugin-infolist.c
+++ b/src/plugins/plugin-infolist.c
@@ -45,7 +45,7 @@ plugin_infolist_new ()
{
struct t_plugin_infolist *new_infolist;
- new_infolist = (struct t_plugin_infolist *)malloc (sizeof (struct t_plugin_infolist));
+ new_infolist = malloc (sizeof (*new_infolist));
if (new_infolist)
{
new_infolist->items = NULL;
@@ -73,7 +73,7 @@ plugin_infolist_new_item (struct t_plugin_infolist *list)
{
struct t_plugin_infolist_item *new_item;
- new_item = (struct t_plugin_infolist_item *)malloc (sizeof (struct t_plugin_infolist_item));
+ new_item = malloc (sizeof (*new_item));
if (new_item)
{
new_item->vars = NULL;
@@ -105,7 +105,7 @@ plugin_infolist_new_var_integer (struct t_plugin_infolist_item *item,
if (!item || !name || !name[0])
return NULL;
- new_var = (struct t_plugin_infolist_var *)malloc (sizeof (struct t_plugin_infolist_var));
+ new_var = malloc (sizeof (*new_var));
if (new_var)
{
new_var->name = strdup (name);
@@ -138,7 +138,7 @@ plugin_infolist_new_var_string (struct t_plugin_infolist_item *item,
if (!item || !name || !name[0])
return NULL;
- new_var = (struct t_plugin_infolist_var *)malloc (sizeof (struct t_plugin_infolist_var));
+ new_var = malloc (sizeof (*new_var));
if (new_var)
{
new_var->name = strdup (name);
@@ -170,7 +170,7 @@ plugin_infolist_new_var_pointer (struct t_plugin_infolist_item *item,
if (!item || !name || !name[0])
return NULL;
- new_var = (struct t_plugin_infolist_var *)malloc (sizeof (struct t_plugin_infolist_var));
+ new_var = malloc (sizeof (*new_var));
if (new_var)
{
new_var->name = strdup (name);
@@ -202,7 +202,7 @@ plugin_infolist_new_var_time (struct t_plugin_infolist_item *item,
if (!item || !name || !name[0])
return NULL;
- new_var = (struct t_plugin_infolist_var *)malloc (sizeof (struct t_plugin_infolist_var));
+ new_var = malloc (sizeof (*new_var));
if (new_var)
{
new_var->name = strdup (name);
@@ -303,7 +303,7 @@ plugin_infolist_get_fields (struct t_plugin_infolist *list)
length += strlen (ptr_var->name) + 3;
}
- list->ptr_item->fields = (char *)malloc ((length + 1) * sizeof (char));
+ list->ptr_item->fields = malloc (length + 1);
if (!list->ptr_item->fields)
return NULL;
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 11864fb40..89f7cbadf 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -247,7 +247,7 @@ plugin_load (char *filename)
}
/* create new plugin */
- new_plugin = (struct t_weechat_plugin *)malloc (sizeof (struct t_weechat_plugin));
+ new_plugin = malloc (sizeof (*new_plugin));
if (new_plugin)
{
/* variables */
@@ -513,7 +513,7 @@ plugin_auto_load ()
}
/* auto-load plugins in WeeChat global lib dir */
- dir_name = (char *)malloc ((strlen (WEECHAT_LIBDIR) + 16) * sizeof (char));
+ dir_name = malloc (strlen (WEECHAT_LIBDIR) + 16);
if (dir_name)
{
snprintf (dir_name, strlen (WEECHAT_LIBDIR) + 16,
diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c
index 9a00906e4..50458c209 100644
--- a/src/plugins/scripts/lua/weechat-lua.c
+++ b/src/plugins/scripts/lua/weechat-lua.c
@@ -105,7 +105,7 @@ weechat_lua_exec (struct t_plugin_script *script,
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = lua_tonumber (lua_current_interpreter, -1);
ret_value = ret_i;
diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c
index 1b2876c03..2ab653233 100644
--- a/src/plugins/scripts/perl/weechat-perl.c
+++ b/src/plugins/scripts/perl/weechat-perl.c
@@ -119,9 +119,9 @@ weechat_perl_exec (struct t_plugin_script *script,
#ifndef MULTIPLICITY
length = strlen (script->interpreter) + strlen (function) + 3;
- func = (char *)malloc (length * sizeof (char));
+ func = malloc (length);
if (!func)
- return NULL;
+ return NULL;
snprintf (func, length, "%s::%s", (char *) script->interpreter, function);
#else
(void) length;
@@ -135,7 +135,7 @@ weechat_perl_exec (struct t_plugin_script *script,
/* are we loading the script file ? */
if (strcmp (function, "weechat_perl_load_eval_file") != 0)
- perl_current_script = script;
+ perl_current_script = script;
count = perl_call_argv (func, G_EVAL | G_SCALAR, argv);
ret_value = NULL;
@@ -149,42 +149,42 @@ weechat_perl_exec (struct t_plugin_script *script,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), "perl", SvPV_nolen (ERRSV));
(void) POPs; /* poping the 'undef' */
- mem_err = 0;
+ mem_err = 0;
}
else
{
if (count != 1)
- {
+ {
weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" must "
"return one valid value (%d)"),
weechat_prefix ("error"), "perl", function, count);
- mem_err = 0;
- }
+ mem_err = 0;
+ }
else
- {
- if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
- {
- ret_s = newSVsv(POPs);
- ret_value = strdup (SvPV_nolen (ret_s));
- SvREFCNT_dec (ret_s);
- }
- else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
- {
- ret_i = (int *)malloc (sizeof (int));
- if (ret_i)
- *ret_i = POPi;
- ret_value = ret_i;
- }
- else
- {
- weechat_printf (NULL,
+ {
+ if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
+ {
+ ret_s = newSVsv(POPs);
+ ret_value = strdup (SvPV_nolen (ret_s));
+ SvREFCNT_dec (ret_s);
+ }
+ else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
+ {
+ ret_i = malloc (sizeof (*ret_i));
+ if (ret_i)
+ *ret_i = POPi;
+ ret_value = ret_i;
+ }
+ else
+ {
+ weechat_printf (NULL,
weechat_gettext ("%s%s: function \"%s\" is "
"internally misused"),
weechat_prefix ("error"), "perl", function);
- mem_err = 0;
- }
- }
+ mem_err = 0;
+ }
+ }
}
PUTBACK;
@@ -197,11 +197,11 @@ weechat_perl_exec (struct t_plugin_script *script,
if (!ret_value && (mem_err == 1))
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: not enough memory in function "
"\"%s\""),
weechat_prefix ("error"), "perl", function);
- return NULL;
+ return NULL;
}
return ret_value;
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c
index 0b7dd6c4f..b259427be 100644
--- a/src/plugins/scripts/python/weechat-python.c
+++ b/src/plugins/scripts/python/weechat-python.c
@@ -137,7 +137,7 @@ weechat_python_exec (struct t_plugin_script *script,
else if (PyInt_Check (rc) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = (int) PyInt_AsLong(rc);
ret_value = ret_i;
@@ -277,8 +277,8 @@ weechat_python_load (char *filename)
"sub-interpreter"),
weechat_prefix ("error"), "python");
fclose (fp);
- /* PyEval_ReleaseLock (); */
- return 0;
+ /* PyEval_ReleaseLock (); */
+ return 0;
}
/* PyThreadState_Swap (python_current_interpreter); */
@@ -293,10 +293,10 @@ weechat_python_load (char *filename)
weechat_prefix ("error"), "python");
fclose (fp);
- Py_EndInterpreter (python_current_interpreter);
+ Py_EndInterpreter (python_current_interpreter);
/* PyEval_ReleaseLock (); */
-
- return 0;
+
+ return 0;
}
/* adding $weechat_dir/python in $PYTHONPATH */
@@ -304,19 +304,19 @@ weechat_python_load (char *filename)
w_home = weechat_info_get ("weechat_dir");
if (w_home)
{
- len = strlen (w_home) + 1 + strlen("python") + 1;
- p_home = (char *)malloc (len * sizeof (char));
- if (p_home)
- {
- snprintf (p_home, len, "%s/python", w_home);
- path = PyString_FromString (p_home);
- if (path != NULL)
- {
- PyList_Insert (python_path, 0, path);
- Py_DECREF (path);
- }
- free (p_home);
- }
+ len = strlen (w_home) + 1 + strlen("python") + 1;
+ p_home = malloc (len);
+ if (p_home)
+ {
+ snprintf (p_home, len, "%s/python", w_home);
+ path = PyString_FromString (p_home);
+ if (path != NULL)
+ {
+ PyList_Insert (python_path, 0, path);
+ Py_DECREF (path);
+ }
+ free (p_home);
+ }
}
/* define some constants */
@@ -344,15 +344,15 @@ weechat_python_load (char *filename)
}
else
{
- if (PySys_SetObject("stdout", weechat_outputs) == -1)
+ if (PySys_SetObject("stdout", weechat_outputs) == -1)
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: unable to redirect stdout"),
weechat_prefix ("error"), "python");
}
- if (PySys_SetObject("stderr", weechat_outputs) == -1)
+ if (PySys_SetObject("stderr", weechat_outputs) == -1)
{
- weechat_printf (NULL,
+ weechat_printf (NULL,
weechat_gettext ("%s%s: unable to redirect stderr"),
weechat_prefix ("error"), "python");
}
@@ -365,22 +365,22 @@ weechat_python_load (char *filename)
weechat_printf (NULL,
weechat_gettext ("%s%s: unable to parse file \"%s\""),
weechat_prefix ("error"), "python", filename);
- fclose (fp);
-
- if (PyErr_Occurred ()) PyErr_Print ();
- Py_EndInterpreter (python_current_interpreter);
- /* PyEval_ReleaseLock (); */
-
- /* if script was registered, removing from list */
- if (python_current_script != NULL)
- {
- script_remove (weechat_python_plugin, &python_scripts,
- python_current_script);
- }
+ fclose (fp);
+
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ Py_EndInterpreter (python_current_interpreter);
+ /* PyEval_ReleaseLock (); */
+
+ /* if script was registered, removing from list */
+ if (python_current_script != NULL)
+ script_remove (weechat_python_plugin, &python_scripts,
+ python_current_script);
return 0;
}
- if (PyErr_Occurred ()) PyErr_Print ();
+ if (PyErr_Occurred ())
+ PyErr_Print ();
fclose (fp);
@@ -391,11 +391,12 @@ weechat_python_load (char *filename)
"found (or failed) in file \"%s\""),
weechat_prefix ("error"), "python", filename);
- if (PyErr_Occurred ()) PyErr_Print ();
- Py_EndInterpreter (python_current_interpreter);
- /* PyEval_ReleaseLock (); */
-
- return 0;
+ if (PyErr_Occurred ())
+ PyErr_Print ();
+ Py_EndInterpreter (python_current_interpreter);
+ /* PyEval_ReleaseLock (); */
+
+ return 0;
}
python_current_script->interpreter = (PyThreadState *) python_current_interpreter;
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index 1736ecda6..dc32998c6 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -198,7 +198,7 @@ weechat_ruby_exec (struct t_plugin_script *script,
}
else if ((TYPE(rc) == T_FIXNUM) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
{
- ret_i = (int *)malloc (sizeof (int));
+ ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = NUM2INT(rc);
ret_value = ret_i;
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index 7f8f42219..52bb09df3 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -911,8 +911,8 @@ script_api_config_get_plugin (struct t_weechat_plugin *weechat_plugin,
{
char *option_fullname, *return_value;
- option_fullname = (char *)malloc ((strlen (script->name) +
- strlen (option) + 2) * sizeof (char));
+ option_fullname = malloc ((strlen (script->name) +
+ strlen (option) + 2));
if (!option_fullname)
return NULL;
@@ -939,8 +939,8 @@ script_api_config_set_plugin (struct t_weechat_plugin *weechat_plugin,
char *option_fullname;
int return_code;
- option_fullname = (char *)malloc ((strlen (script->name) +
- strlen (option) + 2) * sizeof (char));
+ option_fullname = malloc ((strlen (script->name) +
+ strlen (option) + 2));
if (!option_fullname)
return 0;
diff --git a/src/plugins/scripts/script-callback.c b/src/plugins/scripts/script-callback.c
index 537375820..fb9ae66ca 100644
--- a/src/plugins/scripts/script-callback.c
+++ b/src/plugins/scripts/script-callback.c
@@ -36,7 +36,7 @@ script_callback_alloc ()
{
struct t_script_callback *new_script_callback;
- new_script_callback = (struct t_script_callback *)malloc (sizeof (struct t_script_callback));
+ new_script_callback = malloc (sizeof (*new_script_callback));
if (new_script_callback)
{
new_script_callback->script = NULL;
diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c
index 53f9dc425..c7c5d507f 100644
--- a/src/plugins/scripts/script.c
+++ b/src/plugins/scripts/script.c
@@ -101,7 +101,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add hook for config option */
length = strlen (weechat_plugin->name) + 32;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s.%s",
@@ -114,7 +114,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* create directories in WeeChat home */
weechat_mkdir_home (weechat_plugin->name, 0755);
length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s/autoload", weechat_plugin->name);
@@ -124,7 +124,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add command */
length = strlen (completion) + strlen (weechat_plugin->name) + 16;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s|%%(%s_script)",
@@ -146,7 +146,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
/* add completion */
length = strlen (weechat_plugin->name) + 16;
- string = (char *)malloc (length * sizeof (char));
+ string = malloc (length);
if (string)
{
snprintf (string, length, "%s_script", weechat_plugin->name);
@@ -214,7 +214,7 @@ script_auto_load (struct t_weechat_plugin *weechat_plugin,
if (!dir_home)
return;
dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
- dir_name = (char *)malloc (dir_length * sizeof (char));
+ dir_name = malloc (dir_length);
if (!dir_name)
return;
@@ -264,7 +264,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
if (!dir_home)
return NULL;
length = strlen (dir_home) + strlen (filename + 1) + 1;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length, "%s%s", dir_home, filename + 1);
@@ -279,7 +279,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat user's autoload dir */
length = strlen (dir_home) + strlen (weechat_plugin->name) + 8 +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -293,7 +293,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat language user's dir */
length = strlen (dir_home) + strlen (weechat_plugin->name) +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -305,7 +305,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
/* try WeeChat user's dir */
length = strlen (dir_home) + strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name, length,
@@ -322,7 +322,7 @@ script_search_full_name (struct t_weechat_plugin *weechat_plugin,
{
length = strlen (dir_system) + strlen (weechat_plugin->name) +
strlen (filename) + 16;
- final_name = (char *)malloc (length * sizeof (char));
+ final_name = malloc (length);
if (final_name)
{
snprintf (final_name,length,
@@ -369,7 +369,7 @@ script_add (struct t_weechat_plugin *weechat_plugin,
license, name, weechat_plugin->license);
}
- new_script = (struct t_plugin_script *)malloc (sizeof (struct t_plugin_script));
+ new_script = malloc (sizeof (*new_script));
if (new_script)
{
new_script->filename = strdup (filename);
diff --git a/src/plugins/trigger/trigger-libc.c b/src/plugins/trigger/trigger-libc.c
index 463fe1905..7602f7738 100644
--- a/src/plugins/trigger/trigger-libc.c
+++ b/src/plugins/trigger/trigger-libc.c
@@ -85,7 +85,7 @@ c_strndup (char *string, int length)
if ((int)strlen (string) < length)
return strdup (string);
- result = (char *)malloc ((length + 1) * sizeof (char));
+ result = malloc (length + 1);
if (!result)
return NULL;
@@ -159,7 +159,7 @@ c_weechat_strreplace (char *string, char *search, char *replace)
length_new = strlen (string) - (count * length1) + (count * length2) + 1;
/* allocate new string */
- new_string = (char *)malloc (length_new * sizeof (char));
+ new_string = malloc (length_new);
if (!new_string)
return strdup (string);
@@ -215,9 +215,8 @@ c_explode_string (char *string, char *separators, int num_items_max,
n_items = i;
}
- array =
- (char **)malloc ((num_items_max ? n_items : n_items + 1) *
- sizeof (char *));
+ array = malloc ((num_items_max ? n_items : n_items + 1) *
+ sizeof (array[0]));
ptr1 = string;
ptr2 = string;
@@ -239,8 +238,7 @@ c_explode_string (char *string, char *separators, int num_items_max,
{
if (ptr2 - ptr1 > 0)
{
- array[i] =
- (char *)malloc ((ptr2 - ptr1 + 1) * sizeof (char));
+ array[i] = malloc (ptr2 - ptr1 + 1);
array[i] = strncpy (array[i], ptr1, ptr2 - ptr1);
array[i][ptr2 - ptr1] = '\0';
ptr1 = ++ptr2;
@@ -309,11 +307,11 @@ c_split_multi_command (char *command, char sep)
ptr = ++p;
}
- array = (char **)malloc ((nb_substr + 1) * sizeof(char *));
+ array = malloc ((nb_substr + 1) * sizeof(array[0]));
if (!array)
return NULL;
- buffer = (char *)malloc ((strlen(command) + 1) * sizeof (char));
+ buffer = malloc ((strlen(command) + 1));
if (!buffer)
{
free (array);
@@ -363,7 +361,7 @@ c_split_multi_command (char *command, char sep)
free (buffer);
- array = (char **)realloc (array, (arr_idx + 1) * sizeof(char *));
+ array = realloc (array, (arr_idx + 1) * sizeof(array[0]));
return array;
}
@@ -405,7 +403,7 @@ c_join_string(char **list, char *sep)
len += strlen (list[i]);
len += i*strlen (sep) + 1;
- str = (char *)malloc (len * sizeof(char));
+ str = malloc (len);
if (str)
{
for (i = 0; list[i]; i++)
diff --git a/src/plugins/trigger/trigger-libirc.c b/src/plugins/trigger/trigger-libirc.c
index 3ba820471..a75e75982 100644
--- a/src/plugins/trigger/trigger-libirc.c
+++ b/src/plugins/trigger/trigger-libirc.c
@@ -266,7 +266,7 @@ irc_msg *irc_parse_msg (char *msg)
char *spc1, *spc2;
irc_msg_type *it;
- m = (irc_msg *) malloc(sizeof(irc_msg));
+ m = malloc(sizeof(*m));
if (m)
{
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index ae03d910d..88daa3623 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -45,7 +45,7 @@ t_weechat_trigger *weechat_trigger_alloc (char *pattern, char *domain, char *com
{
t_weechat_trigger *new;
- new = (t_weechat_trigger *)malloc (sizeof (t_weechat_trigger));
+ new = malloc (sizeof (*new));
if (new)
{
new->pattern = strdup (pattern);
@@ -733,7 +733,7 @@ weechat_trigger_edit (t_weechat_plugin *plugin, int todo)
return -1;
len = strlen (weechat_dir) + strlen(DIR_SEP) + strlen(CONF_FILE) + 1;
- triggerrc = (char *)malloc (len * sizeof(char));
+ triggerrc = malloc (len);
if (!triggerrc)
return -1;