Allow shrinking of array.
This commit is contained in:
parent
c14b687209
commit
fff301e3e2
|
@ -133,10 +133,13 @@ int getJSONValue(cJSON *node, char *name, int defValue)
|
||||||
void *resize(void *array, int oldSize, int newSize)
|
void *resize(void *array, int oldSize, int newSize)
|
||||||
{
|
{
|
||||||
void **newArray;
|
void **newArray;
|
||||||
|
int copySize;
|
||||||
|
|
||||||
|
copySize = newSize > oldSize ? oldSize : newSize;
|
||||||
|
|
||||||
newArray = malloc(newSize);
|
newArray = malloc(newSize);
|
||||||
memset(newArray, 0, newSize);
|
memset(newArray, 0, newSize);
|
||||||
memcpy(newArray, array, oldSize);
|
memcpy(newArray, array, copySize);
|
||||||
free(array);
|
free(array);
|
||||||
|
|
||||||
return newArray;
|
return newArray;
|
||||||
|
|
Loading…
Reference in New Issue