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

Removed sizeof(char) and useless type casts from void* to another pointer type (patch from Leonid Evdokimov)

This commit is contained in:
Sebastien Helleu
2008-03-23 23:00:04 +01:00
parent 14feea7ab8
commit 57323fa71e
64 changed files with 273 additions and 285 deletions
+6 -6
View File
@@ -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,
+9 -9
View File
@@ -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);
+3 -3
View File
@@ -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;
+3 -4
View File
@@ -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);
+2 -2
View File
@@ -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);
+3 -3
View File
@@ -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;
+3 -3
View File
@@ -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,
+1 -1
View File
@@ -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",
+8 -9
View File
@@ -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);
+4 -5
View File
@@ -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);
}
+1 -1
View File
@@ -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 */
+2 -2
View File
@@ -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)
+13 -14
View File
@@ -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 */
+1 -1
View File
@@ -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;
+5 -6
View File
@@ -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;
+1 -1
View File
@@ -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);
+1 -2
View File
@@ -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;
+3 -5
View File
@@ -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;
+7 -7
View File
@@ -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;
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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;
+29 -29
View File
@@ -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;
+42 -41
View File
@@ -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;
+1 -1
View File
@@ -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;
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -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;
+11 -11
View File
@@ -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);
+9 -11
View File
@@ -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++)
+1 -1
View File
@@ -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)
{
+2 -2
View File
@@ -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;