Browse Source

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.
Sam Lantinga 10 năm trước cách đây
mục cha
commit
c13a077d15
1 tập tin đã thay đổi với 3 bổ sung và 3 xóa
  1. 3 3
      src/audio/SDL_audiotypecvt.c

+ 3 - 3
src/audio/SDL_audiotypecvt.c

@@ -239,7 +239,7 @@ SDL_Upsample_Arbitrary(SDL_AudioCVT *cvt, const int channels)
     SDL_memcpy(sample, src, cpy);
     SDL_memcpy(sample, src, cpy);
     SDL_memcpy(last_sample, src, cpy);
     SDL_memcpy(last_sample, src, cpy);
 
 
-    while (dst >= target) {
+    while (dst > target) {
         SDL_memcpy(dst, sample, cpy);
         SDL_memcpy(dst, sample, cpy);
         dst -= 8;
         dst -= 8;
         eps += srcsize;
         eps += srcsize;
@@ -320,7 +320,7 @@ SDL_Upsample_x2(SDL_AudioCVT *cvt, const int channels)
     SDL_assert(channels <= 8);
     SDL_assert(channels <= 8);
     SDL_memcpy(last_sample, src, cpy);
     SDL_memcpy(last_sample, src, cpy);
 
 
-    while (dst >= target) {
+    while (dst > target) {
         for (i = 0; i < channels; i++) {
         for (i = 0; i < channels; i++) {
             dst[i] = (float) ((((double)src[i]) + ((double)last_sample[i])) * 0.5);
             dst[i] = (float) ((((double)src[i]) + ((double)last_sample[i])) * 0.5);
         }
         }
@@ -355,7 +355,7 @@ SDL_Upsample_x4(SDL_AudioCVT *cvt, const int channels)
     SDL_assert(channels <= 8);
     SDL_assert(channels <= 8);
     SDL_memcpy(last_sample, src, cpy);
     SDL_memcpy(last_sample, src, cpy);
 
 
-    while (dst >= target) {
+    while (dst > target) {
         for (i = 0; i < channels; i++) {
         for (i = 0; i < channels; i++) {
             dst[i] = (float) ((((double) src[i]) + (3.0 * ((double) last_sample[i]))) * 0.25);
             dst[i] = (float) ((((double) src[i]) + (3.0 * ((double) last_sample[i]))) * 0.25);
         }
         }