Rework resize_global_player_data to work with realloc instead of of a combination of malloc and free
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@3644 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
9926852390
commit
d9c154c970
|
@ -384,17 +384,28 @@ static void resize_local_player_data(unsigned int i, unsigned int size)
|
|||
}
|
||||
}
|
||||
|
||||
static void resize_global_player_data(unsigned int i, unsigned int size)
|
||||
static void resize_global_player_data(unsigned int i, size_t size)
|
||||
{
|
||||
if (global_player_data[i].buffer_size < size)
|
||||
void* new_buffer;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
if (global_player_data[i].data != NULL)
|
||||
{
|
||||
free(global_player_data[i].data);
|
||||
}
|
||||
global_player_data[i].data = malloc(size);
|
||||
global_player_data[i].buffer_size = size;
|
||||
free(global_player_data[i].data);
|
||||
global_player_data[i].data = NULL;
|
||||
global_player_data[i].buffer_size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
new_buffer = realloc(global_player_data[i].data, size);
|
||||
if (new_buffer == NULL)
|
||||
{
|
||||
debug(LOG_ERROR, "resize_global_player_data: Out of memory!");
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
|
||||
global_player_data[i].data = new_buffer;
|
||||
global_player_data[i].buffer_size = size;
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue