Fixed bug 3488 - Random crashes (because Memory overlap in audio converters detected by Valgrind)
authorSam Lantinga <slouken@libsdl.org>
Sun, 13 Nov 2016 00:09:02 -0800
changeset 106088661c956c368
parent 10607 264f6495d712
child 10609 d702ecbd8ba7
Fixed bug 3488 - Random crashes (because Memory overlap in audio converters detected by Valgrind)

Vitaly Novichkov

Okay, when I researched code and algorithm, I tried to replace condition "while(dst >= target)" with "while(dst > target)" and crashes are gone.
Seems on some moments it tries to write into the place before memory block begin, therefore phantom crashes appearing after some moments.
src/audio/SDL_audiotypecvt.c
     1.1 --- a/src/audio/SDL_audiotypecvt.c	Fri Nov 11 13:47:40 2016 -0800
     1.2 +++ b/src/audio/SDL_audiotypecvt.c	Sun Nov 13 00:09:02 2016 -0800
     1.3 @@ -239,7 +239,7 @@
     1.4      SDL_memcpy(sample, src, cpy);
     1.5      SDL_memcpy(last_sample, src, cpy);
     1.6  
     1.7 -    while (dst >= target) {
     1.8 +    while (dst > target) {
     1.9          SDL_memcpy(dst, sample, cpy);
    1.10          dst -= 8;
    1.11          eps += srcsize;
    1.12 @@ -320,7 +320,7 @@
    1.13      SDL_assert(channels <= 8);
    1.14      SDL_memcpy(last_sample, src, cpy);
    1.15  
    1.16 -    while (dst >= target) {
    1.17 +    while (dst > target) {
    1.18          for (i = 0; i < channels; i++) {
    1.19              dst[i] = (float) ((((double)src[i]) + ((double)last_sample[i])) * 0.5);
    1.20          }
    1.21 @@ -355,7 +355,7 @@
    1.22      SDL_assert(channels <= 8);
    1.23      SDL_memcpy(last_sample, src, cpy);
    1.24  
    1.25 -    while (dst >= target) {
    1.26 +    while (dst > target) {
    1.27          for (i = 0; i < channels; i++) {
    1.28              dst[i] = (float) ((((double) src[i]) + (3.0 * ((double) last_sample[i]))) * 0.25);
    1.29          }