Allow shrinking of array.

This commit is contained in:
Steve 2016-03-06 09:48:29 +00:00
parent c14b687209
commit fff301e3e2
1 changed files with 4 additions and 1 deletions

View File

@ -133,10 +133,13 @@ int getJSONValue(cJSON *node, char *name, int defValue)
void *resize(void *array, int oldSize, int newSize)
{
void **newArray;
int copySize;
copySize = newSize > oldSize ? oldSize : newSize;
newArray = malloc(newSize);
memset(newArray, 0, newSize);
memcpy(newArray, array, oldSize);
memcpy(newArray, array, copySize);
free(array);
return newArray;