From: Steinar H. Gunderson Date: Tue, 3 May 2016 16:38:23 +0000 (+0200) Subject: Fix an out-of-bounds write (found by asan). X-Git-Tag: 1.3.0~28 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=a1380b251cee714d04d719f724fa1a5b5b54eb1c Fix an out-of-bounds write (found by asan). --- diff --git a/x264_speed_control.cpp b/x264_speed_control.cpp index 3ed3ece..aae7a18 100644 --- a/x264_speed_control.cpp +++ b/x264_speed_control.cpp @@ -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);