aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-23 15:22:37 -0700
committerChris Robinson <[email protected]>2014-03-23 15:22:37 -0700
commit83038c0dab0727b76765a8feed5a2c3c23c9915b (patch)
tree1f03da8314b0d2e97b7d3051d2214057b506747f /Alc/helpers.c
parent55f851093f08bc1274a4b49c85a0651a9f6e9c0f (diff)
Add some integer casts, and a range check
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index a89883ed..59eb359e 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -708,12 +708,17 @@ ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t
vector_ *vecptr = ptr;
void *temp;
+ /* Limit vector sizes to the greatest power-of-two value that an
+ * ALsizei can hold. */
+ if(obj_count > (INT_MAX>>1)+1)
+ return AL_FALSE;
+
/* Use the next power-of-2 size if we don't need to allocate the exact
* amount. This is preferred when regularly increasing the vector since
* it means fewer reallocations. Though it means it also wastes some
* memory. */
if(exact == AL_FALSE)
- obj_count = NextPowerOf2(obj_count);
+ obj_count = NextPowerOf2((ALuint)obj_count);
/* Need to be explicit with the caller type's base size, because it
* could have extra padding before the start of the array (that is,
@@ -722,7 +727,7 @@ ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t
if(temp == NULL) return AL_FALSE;
*vecptr = temp;
- (*vecptr)->Capacity = obj_count;
+ (*vecptr)->Capacity = (ALsizei)obj_count;
}
return AL_TRUE;
}