1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

core: fix bugs with calls to realloc

This commit is contained in:
Sebastien Helleu
2011-08-28 15:25:30 +02:00
parent e411d14b7a
commit f843f904bc
16 changed files with 259 additions and 106 deletions
+13 -2
View File
@@ -97,7 +97,8 @@ void
alias_string_add_word (char **alias, int *length, const char *word)
{
int length_word;
char *alias2;
if (!word)
return;
@@ -112,7 +113,17 @@ alias_string_add_word (char **alias, int *length, const char *word)
}
else
{
*alias = realloc (*alias, strlen (*alias) + length_word + 1);
alias2 = realloc (*alias, strlen (*alias) + length_word + 1);
if (!alias2)
{
if (*alias)
{
free (*alias);
*alias = NULL;
}
return;
}
*alias = alias2;
strcat (*alias, word);
}
*length += length_word;
+17 -5
View File
@@ -176,7 +176,7 @@ irc_mode_channel_set (struct t_irc_server *server,
void
irc_mode_user_add (struct t_irc_server *server, char mode)
{
char str_mode[2];
char str_mode[2], *nick_modes2;
str_mode[0] = mode;
str_mode[1] = '\0';
@@ -185,8 +185,18 @@ irc_mode_user_add (struct t_irc_server *server, char mode)
{
if (!strchr (server->nick_modes, mode))
{
server->nick_modes = realloc (server->nick_modes,
strlen (server->nick_modes) + 1 + 1);
nick_modes2 = realloc (server->nick_modes,
strlen (server->nick_modes) + 1 + 1);
if (!nick_modes2)
{
if (server->nick_modes)
{
free (server->nick_modes);
server->nick_modes = NULL;
}
return;
}
server->nick_modes = nick_modes2;
strcat (server->nick_modes, str_mode);
weechat_bar_item_update ("input_prompt");
}
@@ -206,7 +216,7 @@ irc_mode_user_add (struct t_irc_server *server, char mode)
void
irc_mode_user_remove (struct t_irc_server *server, char mode)
{
char *pos;
char *pos, *nick_modes2;
int new_size;
if (server->nick_modes)
@@ -216,7 +226,9 @@ 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 = realloc (server->nick_modes, new_size);
nick_modes2 = realloc (server->nick_modes, new_size);
if (nick_modes2)
server->nick_modes = nick_modes2;
weechat_bar_item_update ("input_prompt");
}
}
+11 -3
View File
@@ -118,7 +118,7 @@ irc_notify_search (struct t_irc_server *server, const char *nick)
void
irc_notify_set_server_option (struct t_irc_server *server)
{
char *str;
char *str, *str2;
struct t_irc_notify *ptr_notify;
int total_length, length;
@@ -143,7 +143,14 @@ irc_notify_set_server_option (struct t_irc_server *server)
else
{
total_length += length;
str = realloc (str, total_length);
str2 = realloc (str, total_length);
if (!str2)
{
if (str)
free (str);
return;
}
str = str2;
}
if (str)
{
@@ -754,7 +761,8 @@ irc_notify_timer_ison_cb (void *data, int remaining_calls)
message2 = realloc (message, total_length);
if (!message2)
{
free (message);
if (message)
free (message);
message = NULL;
break;
}
+8 -5
View File
@@ -1908,7 +1908,7 @@ IRC_PROTOCOL_CALLBACK(001)
IRC_PROTOCOL_CALLBACK(005)
{
char *pos, *pos2, *pos_start, *error;
char *pos, *pos2, *pos_start, *error, *isupport2;
int length_isupport, length, nick_max_length;
/*
@@ -1961,11 +1961,14 @@ IRC_PROTOCOL_CALLBACK(005)
if (server->isupport)
{
length_isupport = strlen (server->isupport);
server->isupport = realloc (server->isupport,
length_isupport + /* existing */
1 + length + 1); /* new */
if (server->isupport)
isupport2 = realloc (server->isupport,
length_isupport + /* existing */
1 + length + 1); /* new */
if (isupport2)
{
server->isupport = isupport2;
pos_start = server->isupport + length_isupport;
}
}
else
{
+12 -3
View File
@@ -647,6 +647,8 @@ void
irc_redirect_message_add (struct t_irc_redirect *redirect, const char *message,
const char *command)
{
char *output2;
/*
* if command is not for output, then don't add message
* (it is silently ignored)
@@ -659,9 +661,16 @@ irc_redirect_message_add (struct t_irc_redirect *redirect, const char *message,
if (redirect->output)
{
redirect->output_size += strlen("\n") + strlen (message);
redirect->output = realloc (redirect->output, redirect->output_size);
if (redirect->output)
strcat (redirect->output, "\n");
output2 = realloc (redirect->output, redirect->output_size);
if (!output2)
{
free (redirect->output);
redirect->output = NULL;
redirect->output_size = 0;
return;
}
redirect->output = output2;
strcat (redirect->output, "\n");
}
else
{
+9 -4
View File
@@ -1888,23 +1888,28 @@ irc_server_msgq_add_msg (struct t_irc_server *server, const char *msg)
void
irc_server_msgq_add_unterminated (struct t_irc_server *server, const char *string)
{
char *unterminated_message2;
if (!string[0])
return;
if (server->unterminated_message)
{
server->unterminated_message =
unterminated_message2 =
realloc (server->unterminated_message,
(strlen (server->unterminated_message) +
strlen (string) + 1));
if (!server->unterminated_message)
if (!unterminated_message2)
{
weechat_printf (server->buffer,
_("%s%s: not enough memory for received message"),
weechat_prefix ("error"), IRC_PLUGIN_NAME);
free (server->unterminated_message);
server->unterminated_message = NULL;
return;
}
else
strcat (server->unterminated_message, string);
server->unterminated_message = unterminated_message2;
strcat (server->unterminated_message, string);
}
else
{
+9 -2
View File
@@ -469,7 +469,7 @@ void
relay_client_irc_send_join (struct t_relay_client *client,
const char *channel)
{
char *infolist_name, *nicks;
char *infolist_name, *nicks, *nicks2;
const char *nick, *prefix, *topic;
char *host;
int length, length_nicks;
@@ -540,7 +540,14 @@ relay_client_irc_send_join (struct t_relay_client *client,
length_nicks += strlen (nick) + 1 + 1;
if (nicks)
{
nicks = realloc (nicks, length_nicks);
nicks2 = realloc (nicks, length_nicks);
if (!nicks2)
{
if (nicks)
free (nicks);
return;
}
nicks = nicks2;
strcat (nicks, " ");
}
else
+8 -3
View File
@@ -130,7 +130,7 @@ char *
rmodifier_replace_groups (const char *string, regmatch_t regex_match[],
const char *groups)
{
char *result, *str_group, *string_to_add;
char *result, *result2, *str_group, *string_to_add;
const char *ptr_groups;
int length, num_group;
@@ -161,9 +161,14 @@ rmodifier_replace_groups (const char *string, regmatch_t regex_match[],
if (string_to_add)
{
length += strlen (string_to_add);
result = realloc (result, length);
if (!result)
result2 = realloc (result, length);
if (!result2)
{
if (result)
free (result);
return NULL;
}
result = result2;
strcat (result, string_to_add);
free (string_to_add);
}
+10 -5
View File
@@ -817,7 +817,8 @@ void
script_action_add (char **action_list, const char *name)
{
int length;
char *action_list2;
length = strlen (name);
if (!(*action_list))
@@ -828,13 +829,17 @@ script_action_add (char **action_list, const char *name)
}
else
{
*action_list = realloc (*action_list,
action_list2 = realloc (*action_list,
strlen (*action_list) + 1 + length + 1);
if (*action_list)
if (!action_list2)
{
strcat (*action_list, ",");
strcat (*action_list, name);
free (*action_list);
*action_list = NULL;
return;
}
*action_list = action_list2;
strcat (*action_list, ",");
strcat (*action_list, name);
}
}