libavcodec/cinepakenc.c:663: error: Buffer Overrun L3
  Offset: [-1, +oo] Size: 5 by call to `calculate_mode_score`.

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:663:25: Call
661. 
662.                 info.v4_codebook = v4 >= 0 ? v4_codebooks[v4] : NULL;
663.                 score = calculate_mode_score(s, mode, h, v1_size, v4_size, v4, &info);
                             ^
664. 
665.                 //av_log(s->avctx, AV_LOG_INFO, "%3i %3i score = %li\n", v1_size, v4_size, score);

libavcodec/cinepakenc.c:186:1: <Offset trace>
184. }
185. 
186. static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)
     ^
187. {
188.     //score = FF_LAMBDA_SCALE * error + lambda * bits

libavcodec/cinepakenc.c:186:1: Parameter `v4`
  184. }
  185. 
  186. static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)
       ^
  187. {
  188.     //score = FF_LAMBDA_SCALE * error + lambda * bits

libavcodec/cinepakenc.c:186:1: <Length trace>
184. }
185. 
186. static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)
     ^
187. {
188.     //score = FF_LAMBDA_SCALE * error + lambda * bits

libavcodec/cinepakenc.c:186:1: Parameter `s->mb->v4_error[*]`
  184. }
  185. 
  186. static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)
       ^
  187. {
  188.     //score = FF_LAMBDA_SCALE * error + lambda * bits

libavcodec/cinepakenc.c:217:57: Array access: Offset: [-1, +oo] Size: 5 by call to `calculate_mode_score` 
  215.             mb = &s->mb[x];
  216.             score1 = s->lambda * 9  + FF_LAMBDA_SCALE * mb->v1_error;
  217.             score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error[v4];
                                                               ^
  218. 
  219.             if(score1 <= score2) {

static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)
{
    int x;
    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;
    int mb_count = s->w * h / MB_AREA;
    mb_info *mb;
    int64_t score1, score2, score3;
    int64_t ret = s->lambda * ((v1_size ? CHUNK_HEADER_SIZE + v1_size * entry_size : 0) +
                   (v4_size ? CHUNK_HEADER_SIZE + v4_size * entry_size : 0) +
                   CHUNK_HEADER_SIZE) << 3;
    switch(mode) {
    case MODE_V1_ONLY:
        ret += s->lambda * 8 * mb_count;
        for(x = 0; x < mb_count; x++) {
            mb = &s->mb[x];
            ret += FF_LAMBDA_SCALE * mb->v1_error;
            mb->best_encoding = ENC_V1;
        }
        break;
    case MODE_V1_V4:
        for(x = 0; x < mb_count; x++) {
            mb = &s->mb[x];
            score1 = s->lambda * 9  + FF_LAMBDA_SCALE * mb->v1_error;
            score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error[v4];
            if(score1 <= score2) {
                ret += score1;
                mb->best_encoding = ENC_V1;
            } else {
                ret += score2;
                mb->best_encoding = ENC_V4;
            }
        }
        break;
    case MODE_MC:
        for(x = 0; x < mb_count; x++) {
            mb = &s->mb[x];
            score1 = s->lambda * 1  + FF_LAMBDA_SCALE * mb->skip_error;
            score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error;
            score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error[v4];
            if(score1 <= score2 && score1 <= score3) {
                ret += score1;
                mb->best_encoding = ENC_SKIP;
            } else if(score2 <= score1 && score2 <= score3) {
                ret += score2;
                mb->best_encoding = ENC_V1;
            } else {
                ret += score3;
                mb->best_encoding = ENC_V4;
            }
        }
        break;
    }
    return ret;
}
['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 int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)\n{\n    int x;\n    int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;\n    int mb_count = s->w * h / MB_AREA;\n    mb_info *mb;\n    int64_t score1, score2, score3;\n    int64_t ret = s->lambda * ((v1_size ? CHUNK_HEADER_SIZE + v1_size * entry_size : 0) +\n                   (v4_size ? CHUNK_HEADER_SIZE + v4_size * entry_size : 0) +\n                   CHUNK_HEADER_SIZE) << 3;\n    switch(mode) {\n    case MODE_V1_ONLY:\n        ret += s->lambda * 8 * mb_count;\n        for(x = 0; x < mb_count; x++) {\n            mb = &s->mb[x];\n            ret += FF_LAMBDA_SCALE * mb->v1_error;\n            mb->best_encoding = ENC_V1;\n        }\n        break;\n    case MODE_V1_V4:\n        for(x = 0; x < mb_count; x++) {\n            mb = &s->mb[x];\n            score1 = s->lambda * 9  + FF_LAMBDA_SCALE * mb->v1_error;\n            score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error[v4];\n            if(score1 <= score2) {\n                ret += score1;\n                mb->best_encoding = ENC_V1;\n            } else {\n                ret += score2;\n                mb->best_encoding = ENC_V4;\n            }\n        }\n        break;\n    case MODE_MC:\n        for(x = 0; x < mb_count; x++) {\n            mb = &s->mb[x];\n            score1 = s->lambda * 1  + FF_LAMBDA_SCALE * mb->skip_error;\n            score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error;\n            score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error[v4];\n            if(score1 <= score2 && score1 <= score3) {\n                ret += score1;\n                mb->best_encoding = ENC_SKIP;\n            } else if(score2 <= score1 && score2 <= score3) {\n                ret += score2;\n                mb->best_encoding = ENC_V1;\n            } else {\n                ret += score3;\n                mb->best_encoding = ENC_V4;\n            }\n        }\n        break;\n    }\n    return ret;\n}']