From: Anton Mitrofanov Date: Sun, 26 Apr 2015 17:51:05 +0000 (+0300) Subject: Fix possible use of uninitialized MVs in lookahead analysis for B-frames X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e08fdc81018489217f4bafe7321a3baf372fac1f;p=libx264 Fix possible use of uninitialized MVs in lookahead analysis for B-frames --- diff --git a/encoder/slicetype.c b/encoder/slicetype.c index 50a31b0f..c4b82ef2 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -612,7 +612,6 @@ static void x264_slicetype_mb_cost( x264_t *h, x264_mb_analysis_t *a, if( b_bidir ) { - int16_t *mvr = fref1->lowres_mvs[0][p1-p0-1][i_mb_xy]; ALIGNED_ARRAY_8( int16_t, dmv,[2],[2] ); m[1].i_pixel = PIXEL_8x8; @@ -624,14 +623,20 @@ static void x264_slicetype_mb_cost( x264_t *h, x264_mb_analysis_t *a, LOAD_HPELS_LUMA( m[1].p_fref, fref1->lowres ); m[1].p_fref_w = m[1].p_fref[0]; - dmv[0][0] = ( mvr[0] * dist_scale_factor + 128 ) >> 8; - dmv[0][1] = ( mvr[1] * dist_scale_factor + 128 ) >> 8; - dmv[1][0] = dmv[0][0] - mvr[0]; - dmv[1][1] = dmv[0][1] - mvr[1]; - CLIP_MV( dmv[0] ); - CLIP_MV( dmv[1] ); - if( h->param.analyse.i_subpel_refine <= 1 ) - M64( dmv ) &= ~0x0001000100010001ULL; /* mv & ~1 */ + if( fref1->lowres_mvs[0][p1-p0-1][0][0] != 0x7FFF ) + { + int16_t *mvr = fref1->lowres_mvs[0][p1-p0-1][i_mb_xy]; + dmv[0][0] = ( mvr[0] * dist_scale_factor + 128 ) >> 8; + dmv[0][1] = ( mvr[1] * dist_scale_factor + 128 ) >> 8; + dmv[1][0] = dmv[0][0] - mvr[0]; + dmv[1][1] = dmv[0][1] - mvr[1]; + CLIP_MV( dmv[0] ); + CLIP_MV( dmv[1] ); + if( h->param.analyse.i_subpel_refine <= 1 ) + M64( dmv ) &= ~0x0001000100010001ULL; /* mv & ~1 */ + } + else + M64( dmv ) = 0; TRY_BIDIR( dmv[0], dmv[1], 0 ); if( M64( dmv ) )