libavcodec/motion_est.c:1627: error: Buffer Overrun L1
  Offset: 8 Size: 4 by call to `get_mb_score`.

libavcodec/motion_est.c:1627:15: Call
1625. 
1626.     if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)
1627.         dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);
                    ^
1628. 
1629.     get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed

libavcodec/motion_est_template.c:163:1: Parameter `ref_index`
  161. }
  162. 
  163. static inline int get_mb_score(MpegEncContext *s, int mx, int my,
       ^
  164.                                int src_index, int ref_index, int size,
  165.                                int h, int add_rate)

libavcodec/motion_est_template.c:186:8: Call
  184. //    assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
  185. 
  186.     d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
              ^
  187.     //FIXME check cbp before adding penalty for (0,0) vector
  188.     if(add_rate && (mx || my || size>0))

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

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

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

libavcodec/motion_est.c:233:16: Call
      231.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
      232.     if(flags&FLAG_DIRECT){
      233.         return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);
                          ^
      234.     }else{
      235.         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:105:1: <Length trace>
103. }
104. 
105. static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
     ^
106.                       const int size, const int h, int ref_index, int src_index,
107.                       me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){

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

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

libavcodec/motion_est.c:134:50: Array access: Offset: 8 Size: 4 by call to `get_mb_score` 
        132.                     if(qpel){
        133.                         c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
        134.                         c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
                                                              ^
        135.                     }else{
        136.                         c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);

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 direct_search(MpegEncContext * s, int mb_x, int mb_y)\n{\n    MotionEstContext * const c= &s->me;\n    int P[10][2];\n    const int mot_stride = s->mb_stride;\n    const int mot_xy = mb_y*mot_stride + mb_x;\n    const int shift= 1+s->quarter_sample;\n    int dmin, i;\n    const int time_pp= s->pp_time;\n    const int time_pb= s->pb_time;\n    int mx, my, xmin, xmax, ymin, ymax;\n    int16_t (*mv_table)[2]= s->b_direct_mv_table;\n    c->current_mv_penalty= c->mv_penalty[1] + MAX_MV;\n    ymin= xmin=(-32)>>shift;\n    ymax= xmax=   31>>shift;\n    if (IS_8X8(s->next_picture.f.mb_type[mot_xy])) {\n        s->mv_type= MV_TYPE_8X8;\n    }else{\n        s->mv_type= MV_TYPE_16X16;\n    }\n    for(i=0; i<4; i++){\n        int index= s->block_index[i];\n        int min, max;\n        c->co_located_mv[i][0] = s->next_picture.f.motion_val[0][index][0];\n        c->co_located_mv[i][1] = s->next_picture.f.motion_val[0][index][1];\n        c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));\n        c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));\n        max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;\n        min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;\n        max+= 16*mb_x + 1;\n        min+= 16*mb_x - 1;\n        xmax= FFMIN(xmax, s->width - max);\n        xmin= FFMAX(xmin, - 16     - min);\n        max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;\n        min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;\n        max+= 16*mb_y + 1;\n        min+= 16*mb_y - 1;\n        ymax= FFMIN(ymax, s->height - max);\n        ymin= FFMAX(ymin, - 16      - min);\n        if(s->mv_type == MV_TYPE_16X16) break;\n    }\n    assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);\n    if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){\n        s->b_direct_mv_table[mot_xy][0]= 0;\n        s->b_direct_mv_table[mot_xy][1]= 0;\n        return 256*256*256*64;\n    }\n    c->xmin= xmin;\n    c->ymin= ymin;\n    c->xmax= xmax;\n    c->ymax= ymax;\n    c->flags     |= FLAG_DIRECT;\n    c->sub_flags |= FLAG_DIRECT;\n    c->pred_x=0;\n    c->pred_y=0;\n    P_LEFT[0]        = av_clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);\n    P_LEFT[1]        = av_clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);\n    if (!s->first_slice_line) {\n        P_TOP[0]      = av_clip(mv_table[mot_xy - mot_stride             ][0], xmin<<shift, xmax<<shift);\n        P_TOP[1]      = av_clip(mv_table[mot_xy - mot_stride             ][1], ymin<<shift, ymax<<shift);\n        P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1         ][0], xmin<<shift, xmax<<shift);\n        P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1         ][1], ymin<<shift, ymax<<shift);\n        P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n        P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n    }\n    dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16);\n    if(c->sub_flags&FLAG_QPEL)\n        dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n    else\n        dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n    if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)\n        dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1);\n    get_limits(s, 16*mb_x, 16*mb_y);\n    mv_table[mot_xy][0]= mx;\n    mv_table[mot_xy][1]= my;\n    c->flags     &= ~FLAG_DIRECT;\n    c->sub_flags &= ~FLAG_DIRECT;\n    return dmin;\n}', 'static inline int get_mb_score(MpegEncContext *s, int mx, int my,\n                               int src_index, int ref_index, int size,\n                               int h, int add_rate)\n{\n    MotionEstContext * const c= &s->me;\n    const int penalty_factor= c->mb_penalty_factor;\n    const int flags= c->mb_flags;\n    const int qpel= flags & FLAG_QPEL;\n    const int mask= 1+2*qpel;\n    me_cmp_func cmp_sub, chroma_cmp_sub;\n    int d;\n    LOAD_COMMON\n    cmp_sub= s->dsp.mb_cmp[size];\n    chroma_cmp_sub= s->dsp.mb_cmp[size+1];\n    d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\n    if(add_rate && (mx || my || size>0))\n        d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;\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}']