libavcodec/cinepakenc.c:669: error: Buffer Overrun L3
  Offset: [-1, +oo] (⇐ [-1, +oo] + [0, +oo]) Size: 5 by call to `encode_mode`.

libavcodec/cinepakenc.c:651:26: Assignment
649.         quantize(s, h, pict, 1, v1_size, -1, &info);
650. 
651.         for(v4_size = 0, v4 = -1; v4_size <= v1_size; v4_size = v4_size ? v4_size << 2 : v1_size >= 4 ? v1_size >> 2 : 1, v4++) {
                              ^
652.             //try all modes
653.             for(CinepakMode mode = 0; mode < MODE_COUNT; mode++) {

libavcodec/cinepakenc.c:669:33: Call
667.                 if(best_size == 0 || score < *best_score) {
668.                     *best_score = score;
669.                     best_size = encode_mode(s, mode, h, v1_size, v4_size, v4, scratch_pict, &info, s->strip_buf + STRIP_HEADER_SIZE);
                                     ^
670.                     best_mode = mode;
671. 

libavcodec/cinepakenc.c:349:1: Parameter `v4`
  347. }
  348. 
  349. static int encode_mode(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, AVPicture *scratch_pict, strip_info *info, unsigned char *buf)
       ^
  350. {
  351.     int x, y, z, flags, bits, temp_size, header_ofs, ret = 0, mb_count = s->w * h / MB_AREA;

libavcodec/cinepakenc.c:377:17: Call
  375.                 decode_v1_vector(s, &sub_scratch, mb, info);
  376.             else if(mode != MODE_V1_ONLY && mb->best_encoding == ENC_V4)
  377.                 decode_v4_vector(s, &sub_scratch, mb->v4_vector[v4], info);
                       ^
  378.         }
  379.     }

libavcodec/cinepakenc.c:335:35: <Offset trace>
333. 
334.     for(i = y = 0; y < 4; y += 2) {
335.         for(x = 0; x < 4; x += 2, i++) {
                                       ^
336.             sub_pict->data[0][x   +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size];
337.             sub_pict->data[0][x+1 +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+1];

libavcodec/cinepakenc.c:335:35: Assignment
    333. 
    334.     for(i = y = 0; y < 4; y += 2) {
    335.         for(x = 0; x < 4; x += 2, i++) {
                                           ^
    336.             sub_pict->data[0][x   +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size];
    337.             sub_pict->data[0][x+1 +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+1];

libavcodec/cinepakenc.c:330:1: <Length trace>
328. 
329. //decodes the V4 vectors in mb into the 4x4 MB pointed to by sub_pict
330. static void decode_v4_vector(CinepakEncContext *s, AVPicture *sub_pict, int *v4_vector, strip_info *info)
     ^
331. {
332.     int i, x, y, entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;

libavcodec/cinepakenc.c:330:1: Parameter `*v4_vector`
    328. 
    329. //decodes the V4 vectors in mb into the 4x4 MB pointed to by sub_pict
    330. static void decode_v4_vector(CinepakEncContext *s, AVPicture *sub_pict, int *v4_vector, strip_info *info)
         ^
    331. {
    332.     int i, x, y, entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;

libavcodec/cinepakenc.c:342:94: Array access: Offset: [-1, +oo] (⇐ [-1, +oo] + [0, +oo]) Size: 5 by call to `encode_mode` 
    340. 
    341.             if(s->pix_fmt == AV_PIX_FMT_YUV420P) {
    342.                 sub_pict->data[1][(x>>1) + (y>>1)*sub_pict->linesize[1]] = info->v4_codebook[v4_vector[i]*entry_size+4];
                                                                                                      ^
    343.                 sub_pict->data[2][(x>>1) + (y>>1)*sub_pict->linesize[2]] = info->v4_codebook[v4_vector[i]*entry_size+5];
    344.             }

static void decode_v4_vector(CinepakEncContext *s, AVPicture *sub_pict, int *v4_vector, strip_info *info)
{
    int i, x, y, entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;
    for(i = y = 0; y < 4; y += 2) {
        for(x = 0; x < 4; x += 2, i++) {
            sub_pict->data[0][x   +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size];
            sub_pict->data[0][x+1 +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+1];
            sub_pict->data[0][x   + (y+1)*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+2];
            sub_pict->data[0][x+1 + (y+1)*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+3];
            if(s->pix_fmt == AV_PIX_FMT_YUV420P) {
                sub_pict->data[1][(x>>1) + (y>>1)*sub_pict->linesize[1]] = info->v4_codebook[v4_vector[i]*entry_size+4];
                sub_pict->data[2][(x>>1) + (y>>1)*sub_pict->linesize[2]] = info->v4_codebook[v4_vector[i]*entry_size+5];
            }
        }
    }
}
['static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe, AVPicture *last_pict, AVPicture *pict, AVPicture *scratch_pict, unsigned char *buf, int64_t *best_score)\n{\n    int64_t score = 0;\n    int best_size = 0, v1_size, v4_size, v4, mb_count = s->w * h / MB_AREA;\n    strip_info info;\n    CinepakMode best_mode;\n    int v4_codebooks[CODEBOOK_NUM][CODEBOOK_MAX*VECTOR_MAX];\n    if(!keyframe)\n        calculate_skip_errors(s, h, last_pict, pict, &info);\n    for(v4_size = 1, v4 = 0; v4_size <= 256; v4_size <<= 2, v4++) {\n        info.v4_codebook = v4_codebooks[v4];\n        quantize(s, h, pict, 0, v4_size, v4, &info);\n    }\n    for(v1_size = 1; v1_size <= 256; v1_size <<= 2) {\n        quantize(s, h, pict, 1, v1_size, -1, &info);\n        for(v4_size = 0, v4 = -1; v4_size <= v1_size; v4_size = v4_size ? v4_size << 2 : v1_size >= 4 ? v1_size >> 2 : 1, v4++) {\n            for(CinepakMode mode = 0; mode < MODE_COUNT; mode++) {\n                if(keyframe && mode == MODE_MC)\n                    continue;\n                if(!v4_size && mode != MODE_V1_ONLY)\n                    continue;\n                info.v4_codebook = v4 >= 0 ? v4_codebooks[v4] : NULL;\n                score = calculate_mode_score(s, mode, h, v1_size, v4_size, v4, &info);\n                if(best_size == 0 || score < *best_score) {\n                    *best_score = score;\n                    best_size = encode_mode(s, mode, h, v1_size, v4_size, v4, scratch_pict, &info, s->strip_buf + STRIP_HEADER_SIZE);\n                    best_mode = mode;\n                    av_log(s->avctx, AV_LOG_INFO, "mode %i, %3i, %3i: %18li %i B\\n", mode, v1_size, v4_size, score, best_size);\n#ifdef CINEPAKENC_DEBUG\n                    memcpy(s->best_mb, s->mb, mb_count*sizeof(mb_info));\n#endif\n                    write_strip_header(s, y, h, keyframe, s->strip_buf, best_size);\n                }\n            }\n        }\n    }\n#ifdef CINEPAKENC_DEBUG\n    if(best_mode == MODE_V1_ONLY) {\n        s->num_v1_mode++;\n        s->num_v1_encs += s->w*h/MB_AREA;\n    } else {\n        if(best_mode == MODE_V1_V4)\n            s->num_v4_mode++;\n        else\n            s->num_mc_mode++;\n        int x;\n        for(x = 0; x < s->w*h/MB_AREA; x++)\n            if(s->best_mb[x].best_encoding == ENC_V1)\n                s->num_v1_encs++;\n            else if(s->best_mb[x].best_encoding == ENC_V4)\n                s->num_v4_encs++;\n            else\n                s->num_skips++;\n    }\n#endif\n    best_size += STRIP_HEADER_SIZE;\n    memcpy(buf, s->strip_buf, best_size);\n    return best_size;\n}', 'static int encode_mode(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, AVPicture *scratch_pict, strip_info *info, unsigned char *buf)\n{\n    int x, y, z, flags, bits, temp_size, header_ofs, ret = 0, mb_count = s->w * h / MB_AREA;\n    int needs_extra_bit, should_write_temp;\n    unsigned char temp[64];\n    mb_info *mb;\n    AVPicture sub_scratch;\n    if(v1_size)\n        ret += encode_codebook(s, info->v1_codebook, v1_size, 0x22, 0x26, buf + ret);\n    if(v4_size)\n        ret += encode_codebook(s, info->v4_codebook, v4_size, 0x20, 0x24, buf + ret);\n    for(z = y = 0; y < h; y += MB_SIZE) {\n        for(x = 0; x < s->w; x += MB_SIZE, z++) {\n            mb = &s->mb[z];\n            if(mode == MODE_MC && mb->best_encoding == ENC_SKIP)\n                continue;\n            get_sub_picture(s, x, y, scratch_pict, &sub_scratch);\n            if(mode == MODE_V1_ONLY || mb->best_encoding == ENC_V1)\n                decode_v1_vector(s, &sub_scratch, mb, info);\n            else if(mode != MODE_V1_ONLY && mb->best_encoding == ENC_V4)\n                decode_v4_vector(s, &sub_scratch, mb->v4_vector[v4], info);\n        }\n    }\n    switch(mode) {\n    case MODE_V1_ONLY:\n        ret += write_chunk_header(buf + ret, 0x32, mb_count);\n        for(x = 0; x < mb_count; x++)\n            buf[ret++] = s->mb[x].v1_vector;\n        break;\n    case MODE_V1_V4:\n        header_ofs = ret;\n        ret += CHUNK_HEADER_SIZE;\n        for(x = 0; x < mb_count; x += 32) {\n            flags = 0;\n            for(y = x; y < FFMIN(x+32, mb_count); y++)\n                if(s->mb[y].best_encoding == ENC_V4)\n                    flags |= 1 << (31 - y + x);\n            AV_WB32(&buf[ret], flags);\n            ret += 4;\n            for(y = x; y < FFMIN(x+32, mb_count); y++) {\n                mb = &s->mb[y];\n                if(mb->best_encoding == ENC_V1)\n                    buf[ret++] = mb->v1_vector;\n                else\n                    for(z = 0; z < 4; z++)\n                        buf[ret++] = mb->v4_vector[v4][z];\n            }\n        }\n        write_chunk_header(buf + header_ofs, 0x30, ret - header_ofs - CHUNK_HEADER_SIZE);\n        break;\n    case MODE_MC:\n        header_ofs = ret;\n        ret += CHUNK_HEADER_SIZE;\n        flags = bits = temp_size = 0;\n        for(x = 0; x < mb_count; x++) {\n            mb = &s->mb[x];\n            flags |= (mb->best_encoding != ENC_SKIP) << (31 - bits++);\n            needs_extra_bit = 0;\n            should_write_temp = 0;\n            if(mb->best_encoding != ENC_SKIP) {\n                if(bits < 32)\n                    flags |= (mb->best_encoding == ENC_V4) << (31 - bits++);\n                else\n                    needs_extra_bit = 1;\n            }\n            if(bits == 32) {\n                AV_WB32(&buf[ret], flags);\n                ret += 4;\n                flags = bits = 0;\n                if(mb->best_encoding == ENC_SKIP || needs_extra_bit) {\n                    memcpy(&buf[ret], temp, temp_size);\n                    ret += temp_size;\n                    temp_size = 0;\n                } else\n                    should_write_temp = 1;\n            }\n            if(needs_extra_bit) {\n                flags = (mb->best_encoding == ENC_V4) << 31;\n                bits = 1;\n            }\n            if(mb->best_encoding == ENC_V1)\n                temp[temp_size++] = mb->v1_vector;\n            else if(mb->best_encoding == ENC_V4)\n                for(z = 0; z < 4; z++)\n                    temp[temp_size++] = mb->v4_vector[v4][z];\n            if(should_write_temp) {\n                memcpy(&buf[ret], temp, temp_size);\n                ret += temp_size;\n                temp_size = 0;\n            }\n        }\n        if(bits > 0) {\n            AV_WB32(&buf[ret], flags);\n            ret += 4;\n            memcpy(&buf[ret], temp, temp_size);\n            ret += temp_size;\n        }\n        write_chunk_header(buf + header_ofs, 0x31, ret - header_ofs - CHUNK_HEADER_SIZE);\n        break;\n    }\n    return ret;\n}', 'static void decode_v4_vector(CinepakEncContext *s, AVPicture *sub_pict, int *v4_vector, strip_info *info)\n{\n    int i, x, y, entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;\n    for(i = y = 0; y < 4; y += 2) {\n        for(x = 0; x < 4; x += 2, i++) {\n            sub_pict->data[0][x   +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size];\n            sub_pict->data[0][x+1 +     y*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+1];\n            sub_pict->data[0][x   + (y+1)*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+2];\n            sub_pict->data[0][x+1 + (y+1)*sub_pict->linesize[0]] = info->v4_codebook[v4_vector[i]*entry_size+3];\n            if(s->pix_fmt == AV_PIX_FMT_YUV420P) {\n                sub_pict->data[1][(x>>1) + (y>>1)*sub_pict->linesize[1]] = info->v4_codebook[v4_vector[i]*entry_size+4];\n                sub_pict->data[2][(x>>1) + (y>>1)*sub_pict->linesize[2]] = info->v4_codebook[v4_vector[i]*entry_size+5];\n            }\n        }\n    }\n}']