From 8c9c3eb6a4804c569174c09210d6b3db04432289 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sat, 9 Feb 2019 11:40:42 -0600 Subject: [PATCH] Fix buffer overrun. --- apu/resampler.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apu/resampler.h b/apu/resampler.h index 322cb744..a888f591 100644 --- a/apu/resampler.h +++ b/apu/resampler.h @@ -95,12 +95,12 @@ struct Resampler return true; } - inline void push(int16_t l, int16_t r) + inline void push_sample(int16_t l, int16_t r) { if (space_empty() >= 2) { int end = start + size; - if (end > buffer_size) + if (end >= buffer_size) end -= buffer_size; buffer[end] = l; buffer[end + 1] = r; @@ -199,9 +199,10 @@ struct Resampler return (int)trunc(((size >> 1) - r_frac) / r_step) * 2; } - inline void resize(int num_samples) + void resize(int num_samples) { - delete[] buffer; + if (buffer) + delete[] buffer; buffer_size = num_samples; buffer = new int16_t[buffer_size]; clear();