At least this statement
array->values = realloc(array->values, array->capacity);
shall be rewritten like
array->values = realloc(array->values, array->capacity * sizeof( Value ) );
Though it would be more safer to use an intermediate pointer like for example
Value *tmp = realloc(array->values, array->capacity * sizeof( Value ) );
if ( tmp != NULL )
{
array->values = tmp;
// and so on
}
1
solved Dynamically allocated C array suddenly getting modified [closed]