diff --git a/src/core/wee-command.c b/src/core/wee-command.c index febc05c52..65cedc6a1 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -363,7 +363,7 @@ command_builtin (void *data, struct t_gui_buffer *buffer, else { length = strlen (argv_eol[1]) + 2; - command = (char *)malloc (length); + command = (char *)malloc (length * sizeof (char)); if (command) { snprintf (command, length, "/%s", argv_eol[1]); diff --git a/src/core/wee-input.c b/src/core/wee-input.c index 8bf118294..ed1c34587 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -126,9 +126,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); + unknown_command = (char *)malloc ((strlen (command + 1) + 1 + strlen (ptr_args) + 1) * sizeof (char)); else - unknown_command = (char *)malloc (strlen (command + 1) + 1); + unknown_command = (char *)malloc ((strlen (command + 1) + 1) * sizeof (char)); if (unknown_command) { diff --git a/src/core/wee-log.c b/src/core/wee-log.c index 9dc0ced15..e7229797e 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -204,7 +204,7 @@ log_crash_rename () log_close (); length = strlen (weechat_home) + 128; - new_name = (char *)malloc (length); + new_name = (char *)malloc (length * sizeof (char)); if (new_name) { time_now = time (NULL); diff --git a/src/core/wee-string.c b/src/core/wee-string.c index b1728d578..0fdd4d2eb 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); + result = (char *)malloc ((length + 1) * sizeof (char)); if (!result) return NULL; @@ -353,7 +353,7 @@ string_convert_hex_chars (char *string) int pos_output; long number; - output = (char *)malloc (strlen (string) + 1); + output = (char *)malloc ((strlen (string) + 1) * sizeof (char)); if (output) { pos_output = 0; @@ -547,11 +547,11 @@ string_split_command (char *command, char separator) ptr = ++p; } - array = (char **)malloc ((nb_substr + 1) * sizeof(char *)); + array = (char **)malloc ((nb_substr + 1) * sizeof (char *)); if (!array) return NULL; - buffer = (char *)malloc ( (strlen(command) + 1) * sizeof (char)); + buffer = (char *)malloc ((strlen(command) + 1) * sizeof (char)); if (!buffer) { free (array); @@ -652,7 +652,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); + outbuf = (char *)malloc ((outbytesleft + 2) * sizeof (char)); ptr_outbuf = outbuf; ptr_inbuf_shift = NULL; done = 0; diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 8c7b1bee2..4f9419860 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); + (*string) = (char *)malloc ((length + 1) * sizeof (char)); if (!(*string)) return 0; diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 40b8ca4cc..dec328343 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -220,7 +220,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); + name_with_ext = (char *)malloc (length * sizeof (char)); if (!name_with_ext) return strdup (filename); strcpy (name_with_ext, filename); @@ -232,7 +232,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); + final_name = (char *)malloc (length * sizeof (char)); if (!final_name) { free (name_with_ext); @@ -250,7 +250,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); + final_name = (char *)malloc (length * sizeof (char)); if (!final_name) { free (name_with_ext); diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index cacb8ec46..dcd7428bb 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -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); + *color->string = (char *)malloc (4 * sizeof (char)); if (*color->string) snprintf (*color->string, 4, "%s%02d", @@ -278,7 +278,7 @@ gui_color_build (int number, int foreground, int background) 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); + new_color->string = (char *)malloc (4 * sizeof (char)); if (new_color->string) snprintf (new_color->string, 4, "%s%02d", diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c index 1f0eb5337..b33bdcdd5 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 = (char *)malloc((size + 1) * sizeof(*gui_input_clipboard)); if (gui_input_clipboard) { diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 72add97f4..c7fc0d4b6 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -134,8 +134,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); - new_buffer->input_buffer_color_mask = (char *)malloc (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[0] = '\0'; new_buffer->input_buffer_color_mask[0] = '\0'; new_buffer->input_buffer_size = 0; diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index d41572815..6b34b758c 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); + out = (unsigned char *)malloc (out_length * sizeof (unsigned char)); if (!out) return NULL; diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 12cc974f6..9d8b5a974 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); + result = (char *)malloc ((strlen (string) + 1) * sizeof (char)); pos = result; while (string[0]) { @@ -947,7 +947,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); + completion->base_word = (char *)malloc ((pos_end - pos_start + 2) * sizeof (char)); 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'; @@ -972,7 +972,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); + completion->base_command = (char *)malloc ((pos_end - pos_start + 2) * sizeof (char)); 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-input.c b/src/gui/gui-input.c index 3dbc1c831..a38ba6765 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); + buffer->input_buffer = realloc (buffer->input_buffer, optimal_size * sizeof (char)); buffer->input_buffer_color_mask = realloc (buffer->input_buffer_color_mask, - optimal_size); + optimal_size * sizeof (char)); } } } @@ -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); + string2 = (char *)malloc ((size + 2) * sizeof (char)); if (string2) { snprintf (string2, size + 2, "*%s", string); diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 47aec611c..17e248ec0 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -245,7 +245,7 @@ gui_keyboard_get_internal_code (char *key) { char *result; - if ((result = (char *)malloc (strlen (key) + 1))) + if ((result = (char *)malloc ((strlen (key) + 1) * sizeof (char)))) { result[0] = '\0'; while (key[0]) @@ -288,7 +288,7 @@ gui_keyboard_get_expanded_name (char *key) { char *result; - if ((result = (char *)malloc ((strlen (key) * 5) + 1))) + if ((result = (char *)malloc (((strlen (key) * 5) + 1) * sizeof (char)))) { result[0] = '\0'; while (key[0]) @@ -735,7 +735,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); + gui_keyboard_buffer = realloc (gui_keyboard_buffer, optimal_size * sizeof (char)); } } diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 8655b5519..24338acc6 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -81,12 +81,12 @@ alias_add_word (char **alias, int *length, char *word) if (*alias == NULL) { - *alias = (char *)malloc (length_word + 1); + *alias = (char *)malloc ((length_word + 1) * sizeof (char)); strcpy (*alias, word); } else { - *alias = realloc (*alias, strlen (*alias) + length_word + 1); + *alias = realloc (*alias, (strlen (*alias) + length_word + 1) * sizeof (char)); strcat (*alias, word); } *length += length_word; @@ -221,7 +221,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); + alias_command = (char *)malloc ((1 + strlen(args_replaced) + 1) * sizeof (char)); if (alias_command) { strcpy (alias_command, "/"); @@ -241,7 +241,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); + alias_command = (char *)malloc ((1 + length1 + 1 + length2 + 1) * sizeof (char)); if (alias_command) { if (*ptr_cmd[0] != '/') @@ -263,7 +263,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); + alias_command = (char *)malloc ((1 + strlen (*ptr_cmd) + 1) * sizeof (char)); if (alias_command) { strcpy (alias_command, "/"); diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index 521292b81..2f2b1b381 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -483,7 +483,7 @@ charset_get (char *type, char *name) int length; length = strlen (type) + 1 + strlen (name) + 1; - option_name = (char *)malloc (length); + option_name = (char *)malloc (length * sizeof (char)); if (option_name) { snprintf (option_name, length, "%s.%s", @@ -582,7 +582,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); + option_name = (char *)malloc (length * sizeof (char)); if (option_name) { rc = 1; diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 5dae603a6..5af2dfe6c 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -243,8 +243,8 @@ fifo_read () ptr_buf = buffer; if (fifo_unterminated) { - buf2 = (char *)malloc (strlen (fifo_unterminated) + - strlen (buffer) + 1); + buf2 = (char *)malloc ((strlen (fifo_unterminated) + + strlen (buffer) + 1) * sizeof (char)); if (buf2) { strcpy (buf2, fifo_unterminated); diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index 2314b8ba5..22d6703f4 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -48,7 +48,6 @@ irc_la_SOURCES = irc.c \ # irc-dcc.c \ # irc-dcc.h \ -# irc-log.c irc_la_LDFLAGS = -module irc_la_LIBADD = $(GNUTLS_LFLAGS) diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index ae2c409c0..938485fe2 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -413,7 +413,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); + name = (char *)malloc ((strlen (channel->name) + 2) * sizeof (char)); 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 b8912edb6..a3c1054e4 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -56,7 +56,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); + out = (unsigned char *)malloc (out_length * sizeof (unsigned char)); if (!out) return NULL; @@ -213,7 +213,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); + out = (unsigned char *)malloc (out_length * sizeof (unsigned char)); if (!out) return NULL; @@ -282,7 +282,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); + out = (unsigned char *)malloc (out_length * sizeof (unsigned char)); if (!out) return NULL; diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 2e8c56feb..25bf05633 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -123,7 +123,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); + command = (char *)malloc (length * sizeof (char)); if (command) { snprintf (command, length, "MODE %s %s", channel, set); @@ -262,7 +262,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); + server->away_message = (char *)malloc ((strlen (arguments) + 1) * sizeof (char)); if (server->away_message) strcpy (server->away_message, arguments); diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index 737f52646..9cc55234a 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -253,7 +253,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); + buf = (char *)malloc (length * sizeof (char)); if (buf) { snprintf (buf, length, "%s!%s", diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c index 020e1be30..021221d9a 100644 --- a/src/plugins/irc/irc-dcc.c +++ b/src/plugins/irc/irc-dcc.c @@ -173,9 +173,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); + ptr_dcc->local_filename = (char *)malloc ((strlen (dir2) + + strlen (ptr_dcc->nick) + + strlen (ptr_dcc->filename) + 4) * sizeof (char)); if (!ptr_dcc->local_filename) return; @@ -207,7 +207,7 @@ irc_dcc_find_filename (struct t_irc_dcc *ptr_dcc) return; } - filename2 = (char *)malloc (strlen (ptr_dcc->local_filename) + 16); + filename2 = (char *)malloc ((strlen (ptr_dcc->local_filename) + 16) * sizeof (char)); if (!filename2) { irc_dcc_close (ptr_dcc, IRC_DCC_FAILED); @@ -983,8 +983,8 @@ irc_dcc_send_request (struct t_irc_server *server, int type, char *nick, free (dir1); return; } - filename2 = (char *)malloc (strlen (dir2) + - strlen (filename) + 4); + filename2 = (char *)malloc ((strlen (dir2) + + strlen (filename) + 4) * sizeof (char)); if (!filename2) { gui_chat_printf_error (server->buffer, @@ -1268,8 +1268,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); + buf2 = (char *)malloc ((strlen (dcc->unterminated_message) + + strlen (buffer) + 1) * sizeof (char)); if (buf2) { strcpy (buf2, dcc->unterminated_message); diff --git a/src/plugins/irc/irc-log.c b/src/plugins/irc/irc-log.c deleted file mode 100644 index bb7714d2e..000000000 --- a/src/plugins/irc/irc-log.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2003-2008 by FlashCode - * See README for License detail, AUTHORS for developers list. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* irc-log.c: log IRC buffers to files */ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "../../core/weechat.h" -#include "irc.h" -#include "../../core/log.h" -#include "../../core/util.h" -#include "../../core/weechat-config.h" - - -/* - * irc_log_get_filename: get filename for an IRC buffer log file - * Note: result has to be free() after use - */ - -char * -irc_log_fet_filename (char *server_name, char *channel_name, int dcc_chat) -{ - int length; - char *log_path, *log_path2; - char *server_name2, *channel_name2; - char *log_filename; - - if (!server_name) - return NULL; - - log_path = weechat_strreplace (cfg_log_path, "~", getenv ("HOME")); - log_path2 = weechat_strreplace (log_path, "%h", weechat_home); - - if (channel_name) - { - server_name2 = NULL; - channel_name2 = weechat_strreplace (channel_name, DIR_SEPARATOR, "_"); - } - else - { - server_name2 = weechat_strreplace (server_name, DIR_SEPARATOR, "_"); - channel_name2 = NULL; - } - - if (!log_path || !log_path2 || (!channel_name && !server_name2) - || (channel_name && !channel_name2)) - { - weechat_log_printf (_("Not enough memory to write log file \"%s\"\n"), - (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path)); - if (log_path) - free (log_path); - if (log_path2) - free (log_path2); - if (server_name2) - free (server_name2); - if (channel_name2) - free (channel_name2); - return NULL; - } - - length = strlen (log_path2) + 128; - if (channel_name2) - length += strlen (channel_name2); - else - length += strlen (server_name2); - - log_filename = (char *) malloc (length); - if (!log_filename) - { - weechat_log_printf (_("Not enough memory to write log file \"%s\"\n"), - (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path)); - free (log_path); - free (log_path2); - if (server_name2) - free (server_name2); - if (channel_name2) - free (channel_name2); - return NULL; - } - - strcpy (log_filename, log_path2); - - free (log_path); - free (log_path2); - - if (log_filename[strlen (log_filename) - 1] != DIR_SEPARATOR_CHAR) - strcat (log_filename, DIR_SEPARATOR); - - /* server buffer */ - if (!channel_name2) - { - strcat (log_filename, server_name2); - strcat (log_filename, "."); - } - - /* DCC chat buffer */ - if (channel_name2 && dcc_chat) - { - strcat (log_filename, "dcc."); - } - - /* channel buffer */ - if (channel_name2) - { - strcat (log_filename, channel_name2); - strcat (log_filename, "."); - } - - /* append WeeChat suffix */ - strcat (log_filename, "weechatlog"); - - if (server_name2) - free (server_name2); - if (channel_name2) - free (channel_name2); - - return log_filename; -} diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index 34c17d1e8..837cfabf1 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -241,7 +241,7 @@ 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); + (strlen (server->nick_modes) + 1 + 1) * sizeof (char)); strcat (server->nick_modes, str_mode); //gui_status_draw (gui_current_window->buffer, 1); //gui_input_draw (gui_current_window->buffer, 1); @@ -249,7 +249,7 @@ irc_mode_user_add (struct t_irc_server *server, char mode) } else { - server->nick_modes = (char *)malloc (2); + server->nick_modes = (char *)malloc (2 * sizeof (char)); strcpy (server->nick_modes, str_mode); //gui_status_draw (gui_current_window->buffer, 1); //gui_input_draw (gui_current_window->buffer, 1); @@ -274,7 +274,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); + new_size * sizeof (char)); //gui_status_draw (gui_current_window->buffer, 1); //gui_input_draw (gui_current_window->buffer, 1); } diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 285b71c04..eb9fd93e5 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1464,7 +1464,7 @@ irc_protocol_cmd_part (struct t_irc_server *server, char *irc_message, char *hos { join_length = strlen (ptr_channel->name) + 1 + strlen (ptr_channel->key) + 1; - join_string = (char *)malloc (join_length); + join_string = (char *)malloc (join_length * sizeof (char)); if (join_string) { snprintf (join_string, join_length, "%s %s", @@ -3823,9 +3823,9 @@ irc_protocol_cmd_324 (struct t_irc_server *server, char *irc_message, char *host { if (ptr_channel->modes) ptr_channel->modes = (char *)realloc (ptr_channel->modes, - strlen (pos_modes) + 1); + (strlen (pos_modes) + 1) * sizeof (char)); else - ptr_channel->modes = (char *)malloc (strlen (pos_modes) + 1); + ptr_channel->modes = (char *)malloc ((strlen (pos_modes) + 1) * sizeof (char)); strcpy (ptr_channel->modes, pos_modes); irc_mode_channel_set (server, ptr_channel, pos_modes); } @@ -4719,7 +4719,7 @@ irc_protocol_cmd_352 (struct t_irc_server *server, char *irc_message, char *host if (ptr_nick->host) free (ptr_nick->host); length = strlen (pos_user) + 1 + strlen (pos_host) + 1; - ptr_nick->host = (char *)malloc (length); + ptr_nick->host = (char *)malloc (length * sizeof (char)); if (ptr_nick->host) snprintf (ptr_nick->host, length, "%s@%s", pos_user, pos_host); irc_nick_set_away (ptr_channel, ptr_nick, diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 96bb9729d..6de2f7046 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -238,7 +238,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); + server->autojoin = (char *)malloc ((strlen (pos_channel) + 2) * sizeof (char)); strcpy (server->autojoin, "#"); strcat (server->autojoin, pos_channel); } @@ -252,10 +252,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); + server->nick2 = (char *)malloc ((strlen (server->nick1) + 2) * sizeof (char)); strcpy (server->nick2, server->nick1); server->nick2 = strcat (server->nick2, "1"); - server->nick3 = (char *)malloc (strlen (server->nick1) + 2); + server->nick3 = (char *)malloc ((strlen (server->nick1) + 2) * sizeof (char)); strcpy (server->nick3, server->nick1); server->nick3 = strcat (server->nick3, "2"); @@ -1098,8 +1098,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); + message->data = (char *)malloc ((strlen (server->unterminated_message) + + strlen (msg) + 1) * sizeof (char)); if (!message->data) { weechat_printf (server->buffer, @@ -1145,8 +1145,8 @@ irc_server_msgq_add_unterminated (struct t_irc_server *server, char *string) { server->unterminated_message = (char *)realloc (server->unterminated_message, - strlen (server->unterminated_message) + - strlen (string) + 1); + (strlen (server->unterminated_message) + + strlen (string) + 1) * sizeof (char)); if (!server->unterminated_message) { weechat_printf (server->buffer, @@ -1283,7 +1283,7 @@ irc_server_msgq_flush () length = strlen (weechat_plugin->name) + 1 + strlen (irc_recv_msgq->server->name) + 1 + ((ptr_chan_nick) ? strlen (ptr_chan_nick) : 0) + 1; - modifier_data = (char *)malloc (length); + modifier_data = (char *)malloc (length * sizeof (char)); if (modifier_data) { if (ptr_chan_nick) diff --git a/src/plugins/logger/logger-tail.c b/src/plugins/logger/logger-tail.c index 83307db39..4ed48dfd6 100644 --- a/src/plugins/logger/logger-tail.c +++ b/src/plugins/logger/logger-tail.c @@ -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); + new_line->data = (char *)malloc ((strlen (pos_eol) + + strlen (part_of_line) + 1) * sizeof (char)); if (!new_line->data) { free (part_of_line); @@ -161,8 +161,8 @@ 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); + new_part_of_line = (char *)malloc ((strlen (buf) + + strlen (part_of_line) + 1) * sizeof (char)); if (!new_part_of_line) { free (part_of_line); @@ -177,7 +177,7 @@ logger_tail_file (char *filename, int n_lines) } else { - part_of_line = (char *)malloc (strlen (buf) + 1); + part_of_line = (char *)malloc ((strlen (buf) + 1) * sizeof (char)); strcpy (part_of_line, buf); } ptr_buf = NULL; diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index bfcfd858a..fd92047da 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -203,7 +203,7 @@ logger_get_filename (struct t_gui_buffer *buffer) if (name2) length += strlen (name2); length += 16; - res = (char *)malloc (length); + res = (char *)malloc (length * sizeof (char)); if (res) { strcpy (res, log_path2); diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 95c6b8c7a..957f7dd13 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -75,8 +75,8 @@ 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); + internal_option = (char *)malloc ((strlen (plugin_name) + + strlen (option_name) + 2) * sizeof (char)); if (!internal_option) return NULL; @@ -223,8 +223,8 @@ 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); + internal_option = (char *)malloc ((strlen (plugin_name) + + strlen (option_name) + 2) * sizeof (char)); if (!internal_option) return 0; diff --git a/src/plugins/plugin-infolist.c b/src/plugins/plugin-infolist.c index cebdc6e87..a05a897c4 100644 --- a/src/plugins/plugin-infolist.c +++ b/src/plugins/plugin-infolist.c @@ -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); + list->ptr_item->fields = (char *)malloc ((length + 1) * sizeof (char)); if (!list->ptr_item->fields) return NULL; diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 449a32923..d841d1c18 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -459,7 +459,7 @@ plugin_auto_load () } /* auto-load plugins in WeeChat global lib dir */ - dir_name = (char *)malloc (strlen (WEECHAT_LIBDIR) + 16); + dir_name = (char *)malloc ((strlen (WEECHAT_LIBDIR) + 16) * sizeof (char)); 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 44967c82b..8df2f8415 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -104,7 +104,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 = (int *)malloc (sizeof (int)); 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 dd278b1f2..776e8d265 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -118,7 +118,7 @@ weechat_perl_exec (struct t_plugin_script *script, #ifndef MULTIPLICITY int length = strlen (script->interpreter) + strlen (function) + 3; - func = (char *)malloc (length * sizeof(char)); + func = (char *)malloc (length * sizeof (char)); if (!func) return NULL; snprintf (func, length, "%s::%s", (char *) script->interpreter, function); @@ -170,7 +170,7 @@ weechat_perl_exec (struct t_plugin_script *script, } else if (ret_type == WEECHAT_SCRIPT_EXEC_INT) { - ret_i = (int *)malloc (sizeof(int)); + ret_i = (int *)malloc (sizeof (int)); if (ret_i) *ret_i = POPi; ret_value = ret_i; diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 76c71859b..51236028f 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -129,7 +129,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 = (int *)malloc (sizeof (int)); if (ret_i) *ret_i = (int) PyInt_AsLong(rc); ret_value = ret_i; @@ -297,7 +297,7 @@ weechat_python_load (char *filename) if (w_home) { len = strlen (w_home) + 1 + strlen("python") + 1; - p_home = (char *)malloc (len * sizeof(char)); + p_home = (char *)malloc (len * sizeof (char)); if (p_home) { snprintf (p_home, len, "%s/python", w_home); diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index c9b90e2ce..9ec073931 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -185,7 +185,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 = (int *)malloc (sizeof (int)); 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 7981282be..e3bc57056 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -844,8 +844,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); + option_fullname = (char *)malloc ((strlen (script->name) + + strlen (option) + 2) * sizeof (char)); if (!option_fullname) return NULL; @@ -872,8 +872,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); + option_fullname = (char *)malloc ((strlen (script->name) + + strlen (option) + 2) * sizeof (char)); if (!option_fullname) return 0; diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 1cf7e4f09..b1f918f36 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); + string = (char *)malloc (length * sizeof (char)); 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, 0644); length = strlen (weechat_plugin->name) + strlen ("/autoload") + 1; - string = (char *)malloc (length); + string = (char *)malloc (length * sizeof (char)); 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); + string = (char *)malloc (length * sizeof (char)); 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); + string = (char *)malloc (length * sizeof (char)); if (string) { snprintf (string, length, "%s_script", weechat_plugin->name); @@ -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); + final_name = (char *)malloc (length * sizeof (char)); 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); + final_name = (char *)malloc (length * sizeof (char)); 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); + final_name = (char *)malloc (length * sizeof (char)); 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); + final_name = (char *)malloc (length * sizeof (char)); 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); + final_name = (char *)malloc (length * sizeof (char)); if (final_name) { snprintf (final_name,length, diff --git a/src/plugins/trigger/trigger-libc.c b/src/plugins/trigger/trigger-libc.c index 5553109c7..463fe1905 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); + result = (char *)malloc ((length + 1) * sizeof (char)); if (!result) return NULL;