]> git.sesse.net Git - nageru/commitdiff
Fix an out-of-bounds write (found by asan).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 3 May 2016 16:38:23 +0000 (18:38 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 3 May 2016 16:38:23 +0000 (18:38 +0200)
x264_speed_control.cpp

index 3ed3ece8e5b95ed0a69d8788511d489eb39217eb..aae7a18eff838e911e915d92424a30e9830641e2 100644 (file)
@@ -176,14 +176,16 @@ void X264SpeedControl::before_frame(float new_buffer_fill, int new_buffer_size,
        timestamp = t;
 
        // update the time predictor
-       int cpu_time = cpu_time_last_frame;
-       cplx_num *= cplx_decay;
-       cplx_den *= cplx_decay;
-       cplx_num += cpu_time / presets[preset].time;
-       ++cplx_den;
-
-       stat.avg_preset += preset;
-       ++stat.den;
+       if (preset >= 0) {
+               int cpu_time = cpu_time_last_frame;
+               cplx_num *= cplx_decay;
+               cplx_den *= cplx_decay;
+               cplx_num += cpu_time / presets[preset].time;
+               ++cplx_den;
+
+               stat.avg_preset += preset;
+               ++stat.den;
+       }
 
        stat.min_buffer = min(buffer_fill, stat.min_buffer);
        stat.max_buffer = max(buffer_fill, stat.max_buffer);