Browse code

resample2: fix potential overflow

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit a39b5e8b323785695fb0e3c0f30bd9e24287db87)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/10/27 21:34:45
Showing 1 changed files
... ...
@@ -227,10 +227,9 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int
227 227
             dst[dst_index] = src[index2>>32];
228 228
             index2 += incr;
229 229
         }
230
-        frac += dst_index * dst_incr_frac;
231 230
         index += dst_index * dst_incr;
232
-        index += frac / c->src_incr;
233
-        frac %= c->src_incr;
231
+        index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr;
232
+        frac   = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
234 233
   }else{
235 234
     for(dst_index=0; dst_index < dst_size; dst_index++){
236 235
         FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask);