From 1390402af1f0d0a69d20d8f7f37c6124f23e97ee Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sat, 16 Feb 2013 08:11:07 +0000 Subject: [PATCH] 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 --- Changelog | 2 ++ source/array.c | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index bf0afff..6d39fd7 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [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) * Applied patches from jdhore to clean up the plugin building diff --git a/source/array.c b/source/array.c index 80c7069..66155c3 100644 --- a/source/array.c +++ b/source/array.c @@ -232,7 +232,7 @@ extern void insert_index (long **index, long *size, long newIndex) long cnt; if (*size) - *index = (long *)RESIZE(*index, long, *size + 1); + RESIZE(*index, long, *size + 1); else { *index = (long *)new_malloc(sizeof(long)); @@ -348,8 +348,8 @@ extern void delete_array (char *name) *ptr = *(ptr + 1); *array = *(array + 1); } - array_info.item = (char**)RESIZE(array_info.item, char *, array_info.size); - array_info.index = (long *)RESIZE(array_info.index, long, array_info.size); + RESIZE(array_info.item, char *, array_info.size); + RESIZE(array_info.index, long, array_info.size); RESIZE(array_array, an_array, array_info.size); } else @@ -666,7 +666,7 @@ BUILT_IN_FUNCTION(function_setitem) } 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; malloc_strcpy(&array->item[item], input); index = find_item(*array, input); @@ -691,7 +691,7 @@ BUILT_IN_FUNCTION(function_setitem) array->index[0] = 0; malloc_strcpy(&array->item[0], input); 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 array_info.item = (char **)new_malloc(sizeof(char *)); array_info.item[array_info.size] = NULL; @@ -892,8 +892,8 @@ BUILT_IN_FUNCTION(function_delitem) array->size--; for(strptr=&(array->item[item]), cnt=item; cnt < array->size; cnt++, strptr++) *strptr = *(strptr + 1); - array->item = (char**)RESIZE(array->item, char *, array->size); - array->index = (long*)RESIZE(array->index, long, array->size); + RESIZE(array->item, char *, array->size); + RESIZE(array->index, long, array->size); } found = 0; }