libavcodec/cinepakenc.c:649: error: Buffer Overrun L1
  Offset: -1 Size: 5 by call to `quantize`.

libavcodec/cinepakenc.c:649:9: Call
647.     for(v1_size = 1; v1_size <= 256; v1_size <<= 2) {
648.         //compute V1 codebook
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++) {

libavcodec/cinepakenc.c:509:1: <Offset trace>
507. }
508. 
509. static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)
     ^
510. {
511.     int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

libavcodec/cinepakenc.c:509:1: Parameter `v4`
  507. }
  508. 
  509. static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)
       ^
  510. {
  511.     int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

libavcodec/cinepakenc.c:509:1: <Length trace>
507. }
508. 
509. static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)
     ^
510. {
511.     int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

libavcodec/cinepakenc.c:509:1: Parameter `s->mb->v4_vector[*]`
  507. }
  508. 
  509. static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)
       ^
  510. {
  511.     int x, y, i, j, k, x2, y2, x3, y3, plane, shift;

libavcodec/cinepakenc.c:587:21: Array access: Offset: -1 Size: 5 by call to `quantize` 
  585.             } else {
  586.                 for(k = 0; k < 4; k++)
  587.                     mb->v4_vector[v4][k] = s->codebook_closest[i+k];
                           ^
  588. 
  589.                 //fill in vq_pict with V4 data

static int quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)
{
    int x, y, i, j, k, x2, y2, x3, y3, plane, shift;
    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;
    int *codebook = v1mode ? info->v1_codebook : info->v4_codebook;
    int64_t total_error = 0;
    uint8_t vq_pict_buf[(MB_AREA*3)/2];
    AVPicture sub_pict, vq_pict;
    for(i = y = 0; y < h; y += MB_SIZE) {
        for(x = 0; x < s->w; x += MB_SIZE, i += v1mode ? 1 : 4) {
            int *base = s->codebook_input + i*entry_size;
            if(v1mode) {
                for(j = y2 = 0; y2 < entry_size; y2 += 2) {
                    for(x2 = 0; x2 < 4; x2 += 2, j++) {
                        plane = y2 < 4 ? 0 : 1 + (x2 >> 1);
                        shift = y2 < 4 ? 0 : 1;
                        x3 = shift ? 0 : x2;
                        y3 = shift ? 0 : y2;
                        base[j] = (pict->data[plane][((x+x3) >> shift) +      ((y+y3) >> shift)      * pict->linesize[plane]] +
                                   pict->data[plane][((x+x3) >> shift) + 1 +  ((y+y3) >> shift)      * pict->linesize[plane]] +
                                   pict->data[plane][((x+x3) >> shift) +     (((y+y3) >> shift) + 1) * pict->linesize[plane]] +
                                   pict->data[plane][((x+x3) >> shift) + 1 + (((y+y3) >> shift) + 1) * pict->linesize[plane]]) >> 2;
                    }
                }
            } else {
                for(j = y2 = 0; y2 < MB_SIZE; y2 += 2) {
                    for(x2 = 0; x2 < MB_SIZE; x2 += 2) {
                        for(k = 0; k < entry_size; k++, j++) {
                            plane = k >= 4 ? k - 3 : 0;
                            if(k >= 4) {
                                x3 = (x+x2) >> 1;
                                y3 = (y+y2) >> 1;
                            } else {
                                x3 = x + x2 + (k & 1);
                                y3 = y + y2 + (k >> 1);
                            }
                            base[j] = pict->data[plane][x3 + y3*pict->linesize[plane]];
                        }
                    }
                }
            }
        }
    }
    ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
    ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);
    vq_pict.data[0] = vq_pict_buf;
    vq_pict.linesize[0] = MB_SIZE;
    vq_pict.data[1] = &vq_pict_buf[MB_AREA];
    vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2);
    vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1;
    for(i = j = y = 0; y < h; y += MB_SIZE) {
        for(x = 0; x < s->w; x += MB_SIZE, j++, i += v1mode ? 1 : 4) {
            mb_info *mb = &s->mb[j];
            get_sub_picture(s, x, y, pict, &sub_pict);
            if(v1mode) {
                mb->v1_vector = s->codebook_closest[i];
                decode_v1_vector(s, &vq_pict, mb, info);
                mb->v1_error = compute_mb_distortion(s, &sub_pict, &vq_pict);
                total_error += mb->v1_error;
            } else {
                for(k = 0; k < 4; k++)
                    mb->v4_vector[v4][k] = s->codebook_closest[i+k];
                decode_v4_vector(s, &vq_pict, mb->v4_vector[v4], info);
                mb->v4_error[v4] = compute_mb_distortion(s, &sub_pict, &vq_pict);
                total_error += mb->v4_error[v4];
            }
        }
    }
    return 0;
}
['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 quantize(CinepakEncContext *s, int h, AVPicture *pict, int v1mode, int size, int v4, strip_info *info)\n{\n    int x, y, i, j, k, x2, y2, x3, y3, plane, shift;\n    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;\n    int *codebook = v1mode ? info->v1_codebook : info->v4_codebook;\n    int64_t total_error = 0;\n    uint8_t vq_pict_buf[(MB_AREA*3)/2];\n    AVPicture sub_pict, vq_pict;\n    for(i = y = 0; y < h; y += MB_SIZE) {\n        for(x = 0; x < s->w; x += MB_SIZE, i += v1mode ? 1 : 4) {\n            int *base = s->codebook_input + i*entry_size;\n            if(v1mode) {\n                for(j = y2 = 0; y2 < entry_size; y2 += 2) {\n                    for(x2 = 0; x2 < 4; x2 += 2, j++) {\n                        plane = y2 < 4 ? 0 : 1 + (x2 >> 1);\n                        shift = y2 < 4 ? 0 : 1;\n                        x3 = shift ? 0 : x2;\n                        y3 = shift ? 0 : y2;\n                        base[j] = (pict->data[plane][((x+x3) >> shift) +      ((y+y3) >> shift)      * pict->linesize[plane]] +\n                                   pict->data[plane][((x+x3) >> shift) + 1 +  ((y+y3) >> shift)      * pict->linesize[plane]] +\n                                   pict->data[plane][((x+x3) >> shift) +     (((y+y3) >> shift) + 1) * pict->linesize[plane]] +\n                                   pict->data[plane][((x+x3) >> shift) + 1 + (((y+y3) >> shift) + 1) * pict->linesize[plane]]) >> 2;\n                    }\n                }\n            } else {\n                for(j = y2 = 0; y2 < MB_SIZE; y2 += 2) {\n                    for(x2 = 0; x2 < MB_SIZE; x2 += 2) {\n                        for(k = 0; k < entry_size; k++, j++) {\n                            plane = k >= 4 ? k - 3 : 0;\n                            if(k >= 4) {\n                                x3 = (x+x2) >> 1;\n                                y3 = (y+y2) >> 1;\n                            } else {\n                                x3 = x + x2 + (k & 1);\n                                y3 = y + y2 + (k >> 1);\n                            }\n                            base[j] = pict->data[plane][x3 + y3*pict->linesize[plane]];\n                        }\n                    }\n                }\n            }\n        }\n    }\n    ff_init_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);\n    ff_do_elbg(s->codebook_input, entry_size, i, codebook, size, 1, s->codebook_closest, &s->randctx);\n    vq_pict.data[0] = vq_pict_buf;\n    vq_pict.linesize[0] = MB_SIZE;\n    vq_pict.data[1] = &vq_pict_buf[MB_AREA];\n    vq_pict.data[2] = vq_pict.data[1] + (MB_AREA >> 2);\n    vq_pict.linesize[1] = vq_pict.linesize[2] = MB_SIZE >> 1;\n    for(i = j = y = 0; y < h; y += MB_SIZE) {\n        for(x = 0; x < s->w; x += MB_SIZE, j++, i += v1mode ? 1 : 4) {\n            mb_info *mb = &s->mb[j];\n            get_sub_picture(s, x, y, pict, &sub_pict);\n            if(v1mode) {\n                mb->v1_vector = s->codebook_closest[i];\n                decode_v1_vector(s, &vq_pict, mb, info);\n                mb->v1_error = compute_mb_distortion(s, &sub_pict, &vq_pict);\n                total_error += mb->v1_error;\n            } else {\n                for(k = 0; k < 4; k++)\n                    mb->v4_vector[v4][k] = s->codebook_closest[i+k];\n                decode_v4_vector(s, &vq_pict, mb->v4_vector[v4], info);\n                mb->v4_error[v4] = compute_mb_distortion(s, &sub_pict, &vq_pict);\n                total_error += mb->v4_error[v4];\n            }\n        }\n    }\n    return 0;\n}']