aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-04-03 11:13:12 -0700
committerChris Robinson <[email protected]>2014-04-03 11:13:12 -0700
commit482fb37b688b94f5aff78a8dc34e78c1e2840058 (patch)
treed32b2e32aa76df381019151b137f420dde3a1ffe /Alc/helpers.c
parent570eb4e1a7efb15a93a8b70e9293de6523b63284 (diff)
Recognize NULL as an empty vector/string
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;
}