ref: 1636c7a43cff83f077710aaa2d37605f18d51c81
parent: 0a599ea3c7f4700d75b7a15db9ebf049326192e6
author: cbagwell <cbagwell>
date: Sun May 20 14:22:36 EDT 2001
Fixed overflow bug in polyphase.
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,10 @@
sox-12.17.2
-----------
+ o Daniel Culbert found and fixed a bug in the polyphase effect
+ that occurs on platforms that rand() can return large values.
+ The bug resulted in polyphase resampling an audio file to a
+ different rate then it said it was.
o Darrick Servis has made major cleanups in the code in regards
to error conditions. Helps people using libst.
o Darrick Servis has added added optional seek functionality sox.
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -201,8 +201,8 @@
for (k=ct; k>1; ) {
int tmp;
- LONG j;
- j = (LONG)rand() + ((LONG)rand()<<13); /* reasonably big */
+ ULONG j;
+ j = (ULONG)(rand()%32768L) + ((ULONG)(rand()%32768L)<<13); /* reasonably big */
j = j % k; /* non-negative! */
k--;
if (j != k) {
@@ -234,6 +234,11 @@
int k;
static int m1[MF],m2[MF];
static int b1[MF],b2[MF];
+
+ memset(m1,0,sizeof(int)*MF);
+ memset(m2,0,sizeof(int)*MF);
+ memset(b1,0,sizeof(int)*MF);
+ memset(b2,0,sizeof(int)*MF);
f_min = numer; if (f_min>denom) f_min = denom;
c_min = 1<<30;