Fix abuses of the RESIZE() macro in array.c, of the form:

x = RESIZE(x, type, size);

which should just be:

RESIZE(x, type, size);

The erroneous use is undefined behaviour according to the C standard, and
causes new versions of gcc (and, apparently, clang) to throw a warning.

Reported by nenolod/moogle.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@227 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2013-02-16 08:11:07 +00:00
parent 934d19aaa2
commit 1390402af1
2 changed files with 9 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2c01] [Changes 1.2c01]
* Fix abuses of the RESIZE macro. Reported by nenolod. (caf)
* Clears up a crash and some build warnings in the acro plugin. (caf) * Clears up a crash and some build warnings in the acro plugin. (caf)
* Applied patches from jdhore to clean up the plugin building * Applied patches from jdhore to clean up the plugin building

View File

@@ -232,7 +232,7 @@ extern void insert_index (long **index, long *size, long newIndex)
long cnt; long cnt;
if (*size) if (*size)
*index = (long *)RESIZE(*index, long, *size + 1); RESIZE(*index, long, *size + 1);
else else
{ {
*index = (long *)new_malloc(sizeof(long)); *index = (long *)new_malloc(sizeof(long));
@@ -348,8 +348,8 @@ extern void delete_array (char *name)
*ptr = *(ptr + 1); *ptr = *(ptr + 1);
*array = *(array + 1); *array = *(array + 1);
} }
array_info.item = (char**)RESIZE(array_info.item, char *, array_info.size); RESIZE(array_info.item, char *, array_info.size);
array_info.index = (long *)RESIZE(array_info.index, long, array_info.size); RESIZE(array_info.index, long, array_info.size);
RESIZE(array_array, an_array, array_info.size); RESIZE(array_array, an_array, array_info.size);
} }
else else
@@ -666,7 +666,7 @@ BUILT_IN_FUNCTION(function_setitem)
} }
else if (item == array->size) else if (item == array->size)
{ {
array->item = (char **)RESIZE(array->item, char *, (array->size + 1)); RESIZE(array->item, char *, (array->size + 1));
array->item[item] = NULL; array->item[item] = NULL;
malloc_strcpy(&array->item[item], input); malloc_strcpy(&array->item[item], input);
index = find_item(*array, input); index = find_item(*array, input);
@@ -691,7 +691,7 @@ BUILT_IN_FUNCTION(function_setitem)
array->index[0] = 0; array->index[0] = 0;
malloc_strcpy(&array->item[0], input); malloc_strcpy(&array->item[0], input);
if (array_info.size) if (array_info.size)
array_info.item = (char **)RESIZE(array_info.item, char *, (array_info.size + 1)); RESIZE(array_info.item, char *, (array_info.size + 1));
else else
array_info.item = (char **)new_malloc(sizeof(char *)); array_info.item = (char **)new_malloc(sizeof(char *));
array_info.item[array_info.size] = NULL; array_info.item[array_info.size] = NULL;
@@ -892,8 +892,8 @@ BUILT_IN_FUNCTION(function_delitem)
array->size--; array->size--;
for(strptr=&(array->item[item]), cnt=item; cnt < array->size; cnt++, strptr++) for(strptr=&(array->item[item]), cnt=item; cnt < array->size; cnt++, strptr++)
*strptr = *(strptr + 1); *strptr = *(strptr + 1);
array->item = (char**)RESIZE(array->item, char *, array->size); RESIZE(array->item, char *, array->size);
array->index = (long*)RESIZE(array->index, long, array->size); RESIZE(array->index, long, array->size);
} }
found = 0; found = 0;
} }