diff src/audio/sdlgenaudiocvt.pl @ 3602:bfa8d34ce03a

Fixed buffer overflows in resamplers. I'm not confident this is a complete fix, but I'm not confident the current resamplers are really worth keeping at all, either.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 28 Dec 2009 08:28:24 +0000
parents 77c3e67f0740
children 8c9cbb623d55
line wrap: on
line diff
--- a/src/audio/sdlgenaudiocvt.pl	Thu Dec 24 21:00:42 2009 +0000
+++ b/src/audio/sdlgenaudiocvt.pl	Mon Dec 28 08:28:24 2009 +0000
@@ -537,15 +537,19 @@
     const int dstsize = cvt->len_cvt $lencvtop $multiple;
 EOF
 
+    my $endcomparison = '!=';
+
     # Upsampling (growing the buffer) needs to work backwards, since we
     #  overwrite the buffer as we go.
     if ($upsample) {
+        $endcomparison = '>';  # dst > target
         print <<EOF;
     $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
     const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels;
     const $fctype *target = ((const $fctype *) cvt->buf) - $channels;
 EOF
     } else {
+        $endcomparison = '<';  # dst < target
         print <<EOF;
     $fctype *dst = ($fctype *) cvt->buf;
     const $fctype *src = ($fctype *) cvt->buf;
@@ -562,7 +566,7 @@
     }
 
     print <<EOF;
-    while (dst != target) {
+    while (dst $endcomparison target) {
 EOF
 
     for (my $i = 0; $i < $channels; $i++) {