From 2c5c37ade115b5efa3f77ce11bc2c4e46b384959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 6 Sep 2014 21:22:36 +0200 Subject: [PATCH] libswresample: move condition to start of loop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids several issue like calculating sum/maxcoef incorrectly due to adding up matrix entries that will be overwritten, as well as out-of-range writes to s->matrix if the maximum allowed number of channels is used. Signed-off-by: Reimar Döffinger --- libswresample/rematrix.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 5da3056ecc..6552a2fea2 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -299,18 +299,20 @@ av_cold static int auto_matrix(SwrContext *s) for(out_i=i=0; i<64; i++){ double sum=0; int in_i=0; + if((out_ch_layout & (1ULL<matrix[out_i][in_i]= matrix[i][j]; else s->matrix[out_i][in_i]= i == j && (in_ch_layout & out_ch_layout & (1ULL<matrix[out_i][in_i]); - if(in_ch_layout & (1ULL<rematrix_volume < 0) maxcoef = -s->rematrix_volume;