1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +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
+18 -9
View File
@@ -1039,7 +1039,7 @@ char **
string_split_command (const char *command, char separator)
{
int nb_substr, arr_idx, str_idx, type;
char **array;
char **array, **array2;
char *buffer, *p;
const char *ptr;
@@ -1105,12 +1105,18 @@ string_split_command (const char *command, char separator)
array[arr_idx++] = strdup (p);
array[arr_idx] = NULL;
free (buffer);
array = realloc (array, (arr_idx + 1) * sizeof(array[0]));
return array;
array2 = realloc (array, (arr_idx + 1) * sizeof(array[0]));
if (!array2)
{
if (array)
free (array);
return NULL;
}
return array2;
}
/*
@@ -1611,7 +1617,7 @@ string_replace_with_hashtable (const char *string,
int *errors)
{
int length, length_value, index_string, index_result;
char *result, *key;
char *result, *result2, *key;
const char *pos_end_name, *ptr_value;
*errors = 0;
@@ -1651,12 +1657,15 @@ string_replace_with_hashtable (const char *string,
{
length_value = strlen (ptr_value);
length += length_value;
result = realloc (result, length);
if (!result)
result2 = realloc (result, length);
if (!result2)
{
if (result)
free (result);
free (key);
return NULL;
}
result = result2;
strcpy (result + index_result, ptr_value);
index_result += length_value;
index_string += pos_end_name - string -
+27 -11
View File
@@ -369,25 +369,41 @@ util_search_full_lib_name (const char *filename, const char *sys_directory)
char *
util_file_get_content (const char *filename)
{
char *buffer;
char *buffer, *buffer2;
FILE *f;
size_t count, fp;
buffer = NULL;
fp = 0;
f = fopen(filename, "r");
if (f) {
while(!feof(f)) {
buffer = (char *) realloc(buffer, (fp + 1024*sizeof(char)));
count = fread(&buffer[fp], sizeof(char), 1024, f);
f = fopen (filename, "r");
if (f)
{
while (!feof (f))
{
buffer2 = (char *) realloc (buffer, (fp + (1024 * sizeof (char))));
if (!buffer2)
{
if (buffer)
free (buffer);
return NULL;
}
buffer = buffer2;
count = fread (&buffer[fp], sizeof(char), 1024, f);
fp += count;
}
buffer = (char *) realloc(buffer, fp + sizeof(char));
buffer2 = (char *) realloc (buffer, fp + sizeof (char));
if (!buffer2)
{
if (buffer)
free (buffer);
return NULL;
}
buffer = buffer2;
buffer[fp] = '\0';
fclose(f);
fclose (f);
}
return buffer;
}