aboutsummaryrefslogtreecommitdiffstats
path: root/alc/ringbuffer.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-10-08 21:52:08 -0700
committerChris Robinson <[email protected]>2019-10-08 21:55:03 -0700
commit963580c2d503eab7c6d8f60a367498ff103bfa3e (patch)
treeca30803987383fd8bbf413ee7fdd33898c97f2da /alc/ringbuffer.cpp
parent7726a06d26e59dc6a8e109af2e268de878c4f606 (diff)
Never return null from CreateRingBuffer
Allocation failure would already throw a bad_alloc anyway, now a size overflow throws an exception too.
Diffstat (limited to 'alc/ringbuffer.cpp')
-rw-r--r--alc/ringbuffer.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/alc/ringbuffer.cpp b/alc/ringbuffer.cpp
index d61f6129..1f72f4b1 100644
--- a/alc/ringbuffer.cpp
+++ b/alc/ringbuffer.cpp
@@ -25,6 +25,7 @@
#include <algorithm>
#include <climits>
#include <cstdint>
+#include <stdexcept>
#include "almalloc.h"
@@ -45,7 +46,8 @@ RingBufferPtr CreateRingBuffer(size_t sz, size_t elem_sz, int limit_writes)
#endif
}
++power_of_two;
- if(power_of_two < sz) return nullptr;
+ if(power_of_two <= sz || power_of_two > std::numeric_limits<size_t>::max()/elem_sz)
+ throw std::overflow_error{"Ring buffer size overflow"};
const size_t bufbytes{power_of_two * elem_sz};
RingBufferPtr rb{new (FamCount{bufbytes}) RingBuffer{bufbytes}};