libavcodec/motion_est.c:937: error: Buffer Overrun L1
  Offset: [8, 9] (⇐ [0, 1] + 8) Size: 4 by call to `cmp`.

libavcodec/motion_est.c:877:1: Parameter `*s->current_picture_ptr->ref_index[*]`
875. }
876. 
877. static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){
     ^
878.     MotionEstContext * const c= &s->me;
879.     Picture *p= s->current_picture_ptr;

libavcodec/motion_est.c:915:13: Assignment
913. 
914.         if(USES_LIST(mb_type, 0)){
915.             int field_select0= p->ref_index[0][4*mb_xy  ];
                 ^
916.             int field_select1= p->ref_index[0][4*mb_xy+2];
917.             assert(field_select0==0 ||field_select0==1);

libavcodec/motion_est.c:937:17: Call
935.             x= p->motion_val[0][xy ][0];
936.             y= p->motion_val[0][xy ][1];
937.             d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
                     ^
938.             x= p->motion_val[0][xy2][0];
939.             y= p->motion_val[0][xy2][1];

libavcodec/motion_est.c:254:1: Parameter `ref_index`
  252.     against a proposed motion-compensated prediction of that block
  253.  */
  254. static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
       ^
  255.                       const int size, const int h, int ref_index, int src_index,
  256.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){

libavcodec/motion_est.c:263:16: Call
  261.     }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)
  262.        && subx==0 && suby==0){
  263.         return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);
                      ^
  264.     }else{
  265.         return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);

libavcodec/motion_est.c:231:1: Parameter `ref_index`
    229. }
    230. 
    231. static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,
         ^
    232.                       const int size, const int h, int ref_index, int src_index,
    233.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){

libavcodec/motion_est.c:235:16: Call
    233.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
    234.     if(flags&FLAG_DIRECT){
    235.         return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
                        ^
    236.     }else{
    237.         return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);

libavcodec/motion_est.c:107:1: <Length trace>
105. }
106. 
107. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
     ^
108.                       const int size, const int h, int ref_index, int src_index,
109.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

libavcodec/motion_est.c:107:1: Parameter `ref_index`
      105. }
      106. 
      107. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
           ^
      108.                       const int size, const int h, int ref_index, int src_index,
      109.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

libavcodec/motion_est.c:114:5: Assignment
      112.     const int hx= subx + (x<<(1+qpel));
      113.     const int hy= suby + (y<<(1+qpel));
      114.     uint8_t * const * const ref= c->ref[ref_index];
               ^
      115.     uint8_t * const * const src= c->src[src_index];
      116.     int d;

libavcodec/motion_est.c:170:50: Array access: Offset: [8, 9] (⇐ [0, 1] + 8) Size: 4 by call to `cmp` 
      168. 
      169.                     c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
      170.                     c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
                                                            ^
      171.                 }
      172.             }

static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
                      const int size, const int h, int ref_index, int src_index,
                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){
    MotionEstContext * const c= &s->me;
    const int stride= c->stride;
    const int hx= subx + (x<<(1+qpel));
    const int hy= suby + (y<<(1+qpel));
    uint8_t * const * const ref= c->ref[ref_index];
    uint8_t * const * const src= c->src[src_index];
    int d;
        assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
        if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
            const int time_pp= s->pp_time;
            const int time_pb= s->pb_time;
            const int mask= 2*qpel+1;
            if(s->mv_type==MV_TYPE_8X8){
                int i;
                for(i=0; i<4; i++){
                    int fx = c->direct_basis_mv[i][0] + hx;
                    int fy = c->direct_basis_mv[i][1] + hy;
                    int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
                    int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
                    int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
                    int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
                    uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
                    if(qpel){
                        c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
                        c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
                    }else{
                        c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
                        c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
                    }
                }
            }else{
                int fx = c->direct_basis_mv[0][0] + hx;
                int fy = c->direct_basis_mv[0][1] + hy;
                int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
                int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
                int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
                int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
                if(qpel){
                    c->qpel_put[1][fxy](c->temp               , ref[0] + (fx>>2) + (fy>>2)*stride               , stride);
                    c->qpel_put[1][fxy](c->temp + 8           , ref[0] + (fx>>2) + (fy>>2)*stride + 8           , stride);
                    c->qpel_put[1][fxy](c->temp     + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride     + 8*stride, stride);
                    c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
                    c->qpel_avg[1][bxy](c->temp               , ref[8] + (bx>>2) + (by>>2)*stride               , stride);
                    c->qpel_avg[1][bxy](c->temp + 8           , ref[8] + (bx>>2) + (by>>2)*stride + 8           , stride);
                    c->qpel_avg[1][bxy](c->temp     + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride     + 8*stride, stride);
                    c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
                }else{
                    assert((fx>>1) + 16*s->mb_x >= -16);
                    assert((fy>>1) + 16*s->mb_y >= -16);
                    assert((fx>>1) + 16*s->mb_x <= s->width);
                    assert((fy>>1) + 16*s->mb_y <= s->height);
                    assert((bx>>1) + 16*s->mb_x >= -16);
                    assert((by>>1) + 16*s->mb_y >= -16);
                    assert((bx>>1) + 16*s->mb_x <= s->width);
                    assert((by>>1) + 16*s->mb_y <= s->height);
                    c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
                    c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
                }
            }
            d = cmp_func(s, c->temp, src[0], stride, 16);
        }else
            d= 256*256*256*32;
    return d;
}
['static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){\n    MotionEstContext * const c= &s->me;\n    Picture *p= s->current_picture_ptr;\n    int mb_xy= mb_x + mb_y*s->mb_stride;\n    int xy= 2*mb_x + 2*mb_y*s->b8_stride;\n    int mb_type= s->current_picture.mb_type[mb_xy];\n    int flags= c->flags;\n    int shift= (flags&FLAG_QPEL) + 1;\n    int mask= (1<<shift)-1;\n    int x, y, i;\n    int d=0;\n    me_cmp_func cmpf= s->dsp.sse[0];\n    me_cmp_func chroma_cmpf= s->dsp.sse[1];\n    if(p_type && USES_LIST(mb_type, 1)){\n        av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\\n");\n        return INT_MAX/2;\n    }\n    assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1));\n    for(i=0; i<4; i++){\n        int xy= s->block_index[i];\n        clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type));\n        clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type));\n    }\n    if(IS_INTERLACED(mb_type)){\n        int xy2= xy  + s->b8_stride;\n        s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;\n        c->stride<<=1;\n        c->uvstride<<=1;\n        if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){\n            av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\\n");\n            return INT_MAX/2;\n        }\n        if(USES_LIST(mb_type, 0)){\n            int field_select0= p->ref_index[0][4*mb_xy  ];\n            int field_select1= p->ref_index[0][4*mb_xy+2];\n            assert(field_select0==0 ||field_select0==1);\n            assert(field_select1==0 ||field_select1==1);\n            init_interlaced_ref(s, 0);\n            if(p_type){\n                s->p_field_select_table[0][mb_xy]= field_select0;\n                s->p_field_select_table[1][mb_xy]= field_select1;\n                *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];\n                *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];\n                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I;\n            }else{\n                s->b_field_select_table[0][0][mb_xy]= field_select0;\n                s->b_field_select_table[0][1][mb_xy]= field_select1;\n                *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];\n                *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];\n                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I;\n            }\n            x= p->motion_val[0][xy ][0];\n            y= p->motion_val[0][xy ][1];\n            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);\n            x= p->motion_val[0][xy2][0];\n            y= p->motion_val[0][xy2][1];\n            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags);\n        }\n        if(USES_LIST(mb_type, 1)){\n            int field_select0= p->ref_index[1][4*mb_xy  ];\n            int field_select1= p->ref_index[1][4*mb_xy+2];\n            assert(field_select0==0 ||field_select0==1);\n            assert(field_select1==0 ||field_select1==1);\n            init_interlaced_ref(s, 2);\n            s->b_field_select_table[1][0][mb_xy]= field_select0;\n            s->b_field_select_table[1][1][mb_xy]= field_select1;\n            *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];\n            *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2];\n            if(USES_LIST(mb_type, 0)){\n                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I;\n            }else{\n                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;\n            }\n            x= p->motion_val[1][xy ][0];\n            y= p->motion_val[1][xy ][1];\n            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);\n            x= p->motion_val[1][xy2][0];\n            y= p->motion_val[1][xy2][1];\n            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);\n        }\n        c->stride>>=1;\n        c->uvstride>>=1;\n    }else if(IS_8X8(mb_type)){\n        if(!(s->flags & CODEC_FLAG_4MV)){\n            av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\\n");\n            return INT_MAX/2;\n        }\n        cmpf= s->dsp.sse[1];\n        chroma_cmpf= s->dsp.sse[1];\n        init_mv4_ref(c);\n        for(i=0; i<4; i++){\n            xy= s->block_index[i];\n            x= p->motion_val[0][xy][0];\n            y= p->motion_val[0][xy][1];\n            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);\n        }\n        s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;\n    }else{\n        if(USES_LIST(mb_type, 0)){\n            if(p_type){\n                *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];\n                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER;\n            }else if(USES_LIST(mb_type, 1)){\n                *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];\n                *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];\n                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR;\n            }else{\n                *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];\n                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD;\n            }\n            x= p->motion_val[0][xy][0];\n            y= p->motion_val[0][xy][1];\n            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);\n        }else if(USES_LIST(mb_type, 1)){\n            *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];\n            s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD;\n            x= p->motion_val[1][xy][0];\n            y= p->motion_val[1][xy][1];\n            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);\n        }else\n            s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;\n    }\n    return d;\n}', 'static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n    if(av_builtin_constant_p(flags) && av_builtin_constant_p(h) && av_builtin_constant_p(size)\n       && av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n       && flags==0 && h==16 && size==0 && subx==0 && suby==0){\n        return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);\n    }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n       && subx==0 && suby==0){\n        return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);\n    }else{\n        return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);\n    }\n}', 'static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n    if(flags&FLAG_DIRECT){\n        return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);\n    }else{\n        return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);\n    }\n}', 'static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n                      const int size, const int h, int ref_index, int src_index,\n                      me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){\n    MotionEstContext * const c= &s->me;\n    const int stride= c->stride;\n    const int hx= subx + (x<<(1+qpel));\n    const int hy= suby + (y<<(1+qpel));\n    uint8_t * const * const ref= c->ref[ref_index];\n    uint8_t * const * const src= c->src[src_index];\n    int d;\n        assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));\n        if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){\n            const int time_pp= s->pp_time;\n            const int time_pb= s->pb_time;\n            const int mask= 2*qpel+1;\n            if(s->mv_type==MV_TYPE_8X8){\n                int i;\n                for(i=0; i<4; i++){\n                    int fx = c->direct_basis_mv[i][0] + hx;\n                    int fy = c->direct_basis_mv[i][1] + hy;\n                    int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));\n                    int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));\n                    int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n                    int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n                    uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);\n                    if(qpel){\n                        c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);\n                        c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);\n                    }else{\n                        c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);\n                        c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);\n                    }\n                }\n            }else{\n                int fx = c->direct_basis_mv[0][0] + hx;\n                int fy = c->direct_basis_mv[0][1] + hy;\n                int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\n                int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\n                int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n                int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n                if(qpel){\n                    c->qpel_put[1][fxy](c->temp               , ref[0] + (fx>>2) + (fy>>2)*stride               , stride);\n                    c->qpel_put[1][fxy](c->temp + 8           , ref[0] + (fx>>2) + (fy>>2)*stride + 8           , stride);\n                    c->qpel_put[1][fxy](c->temp     + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride     + 8*stride, stride);\n                    c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);\n                    c->qpel_avg[1][bxy](c->temp               , ref[8] + (bx>>2) + (by>>2)*stride               , stride);\n                    c->qpel_avg[1][bxy](c->temp + 8           , ref[8] + (bx>>2) + (by>>2)*stride + 8           , stride);\n                    c->qpel_avg[1][bxy](c->temp     + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride     + 8*stride, stride);\n                    c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);\n                }else{\n                    assert((fx>>1) + 16*s->mb_x >= -16);\n                    assert((fy>>1) + 16*s->mb_y >= -16);\n                    assert((fx>>1) + 16*s->mb_x <= s->width);\n                    assert((fy>>1) + 16*s->mb_y <= s->height);\n                    assert((bx>>1) + 16*s->mb_x >= -16);\n                    assert((by>>1) + 16*s->mb_y >= -16);\n                    assert((bx>>1) + 16*s->mb_x <= s->width);\n                    assert((by>>1) + 16*s->mb_y <= s->height);\n                    c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);\n                    c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);\n                }\n            }\n            d = cmp_func(s, c->temp, src[0], stride, 16);\n        }else\n            d= 256*256*256*32;\n    return d;\n}']