shithub: choc

Download patch

ref: 8204450bacabb136ab739f9263956cfabc10c905
parent: 4746d23891ba45977b5f615859455a4ae7ec6f6c
parent: bd954b9413a16314c24c17dc9a4aacce3fa4c529
author: Simon Howard <fraggle+github@gmail.com>
date: Tue Oct 31 20:41:52 EDT 2017

Merge pull request #953 from ericwa/sdl2-branch

Allocate large enough buffer for SDL_ConvertAudio.

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -631,11 +631,15 @@
                           AUDIO_U8, 1, samplerate,
                           mixer_format, mixer_channels, mixer_freq))
     {
-        convertor.buf = chunk->abuf;
         convertor.len = length;
+        convertor.buf = malloc(convertor.len * convertor.len_mult);
+        assert(convertor.buf != NULL);
         memcpy(convertor.buf, data, length);
 
         SDL_ConvertAudio(&convertor);
+
+        memcpy(chunk->abuf, convertor.buf, chunk->alen);
+        free(convertor.buf);
     }
     else
     {