[FFmpeg-devel] [PATCH] avcodec/mpegvideo: Fix all but one tsan warning in fate-vsynth1-mpeg4

wm4 nfxjfg at googlemail.com
Mon Jul 10 12:27:24 EEST 2017


On Mon, 10 Jul 2017 03:19:51 +0200
Michael Niedermayer <michael at niedermayer.cc> wrote:

> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavcodec/mpegvideo.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index e29558b3a2..574b3854e0 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -495,7 +495,20 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
>      // in that case dst may need a reinit
>      if (!s->context_initialized) {
>          int err;
> -        memcpy(s, s1, sizeof(MpegEncContext));
> +#define COPY(x) s->x = s1->x;
> +#define COPYR(a, b) memcpy(&s->a, &s1->a, ((uint8_t*)&s->b) - ((uint8_t*)&s->a))
> +        COPYR(h263_aic,                         qscale);
> +        COPYR(lambda,                           mv_dir);
> +        COPYR(no_rounding,                      dest);
> +        COPYR(mb_index2xy,                      resync_mb_x);
> +        COPYR(next_p_frame_damaged,             h263_aic_dir);
> +        COPYR(h263_slice_structured,            mcsel);
> +        COPYR(quant_precision,                  first_slice_line);
> +        COPYR(flipflop_rounding,                gb);
> +        COPYR(gop_picture_number,               picture_structure);
> +        COPYR(picture_structure,                pblocks);
> +        COPYR(decode_mb,                        er);
> +        COPYR(error_rate,                       noise_reduction);
>  
>          s->avctx                 = dst;
>          s->bitstream_buffer      = NULL;

Please copy every member on its own, instead of doing a strange range
copy, that will break in subtle and unobvious ways if someone reorders
or adds fields.

I thought we were in a state where we wouldn't add such tricky and
easily broken code anymore.


More information about the ffmpeg-devel mailing list