aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 65c956ec..837b19ad 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -753,8 +753,9 @@ void WriteUnlock(RWLock *lock)
ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact)
{
vector_ *vecptr = ptr;
- if((size_t)(*vecptr)->Capacity < obj_count)
+ if((size_t)(*vecptr ? (*vecptr)->Capacity : 0) < obj_count)
{
+ ALsizei old_size = (*vecptr ? (*vecptr)->Size : 0);
void *temp;
/* Limit vector sizes to the greatest power-of-two value that an
@@ -777,6 +778,7 @@ ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t o
*vecptr = temp;
(*vecptr)->Capacity = (ALsizei)obj_count;
+ (*vecptr)->Size = old_size;
}
return AL_TRUE;
}
@@ -784,9 +786,12 @@ ALboolean vector_reserve(void *ptr, size_t base_size, size_t obj_count, size_t o
ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t obj_size)
{
vector_ *vecptr = ptr;
- if(!vector_reserve(vecptr, base_size, obj_count, obj_size, AL_TRUE))
- return AL_FALSE;
- (*vecptr)->Size = (ALsizei)obj_count;
+ if(*vecptr || obj_count > 0)
+ {
+ if(!vector_reserve(vecptr, base_size, obj_count, obj_size, AL_TRUE))
+ return AL_FALSE;
+ (*vecptr)->Size = (ALsizei)obj_count;
+ }
return AL_TRUE;
}