libavcodec/aaccoder.c:501: error: Buffer Overrun L3
  Offset added: 512 Size: [0, +oo].

libavcodec/aaccoder.c:476:1: <Length trace>
474. #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
475. 
476. static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
     ^
477.                                        SingleChannelElement *sce,
478.                                        const float lambda)

libavcodec/aaccoder.c:476:1: Parameter `sce->sf_idx[*]`
474. #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
475. 
476. static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
     ^
477.                                        SingleChannelElement *sce,
478.                                        const float lambda)

libavcodec/aaccoder.c:501:9: Array access: Offset added: 512 Size: [0, +oo]
499. 
500.     if (!qcnt) {
501.         memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
             ^
502.         memset(sce->zeroes, 1, sizeof(sce->zeroes));
503.         return;

static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
                                       SingleChannelElement *sce,
                                       const float lambda)
{
    int q, w, w2, g, start = 0;
    int i, j;
    int idx;
    TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];
    int bandaddr[TRELLIS_STAGES];
    int minq;
    float mincost;
    float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
    int q0, q1, qcnt = 0;
    for (i = 0; i < 1024; i++) {
        float t = fabsf(sce->coeffs[i]);
        if (t > 0.0f) {
            q0f = FFMIN(q0f, t);
            q1f = FFMAX(q1f, t);
            qnrgf += t*t;
            qcnt++;
        }
    }
    if (!qcnt) {
        memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
        memset(sce->zeroes, 1, sizeof(sce->zeroes));
        return;
    }
    q0 = av_clip_uint8(log2(q0f)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
    q1 = av_clip_uint8(log2(q1f)*4 +  6 + SCALE_ONE_POS - SCALE_DIV_512);
    if (q1 - q0 > 60) {
        int q0low  = q0;
        int q1high = q1;
        int qnrg = av_clip_uint8(log2(sqrt(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
        q1 = qnrg + 30;
        q0 = qnrg - 30;
        if (q0 < q0low) {
            q1 += q0low - q0;
            q0  = q0low;
        } else if (q1 > q1high) {
            q0 -= q1 - q1high;
            q1  = q1high;
        }
    }
    for (i = 0; i < TRELLIS_STATES; i++) {
        paths[0][i].cost    = 0.0f;
        paths[0][i].prev    = -1;
    }
    for (j = 1; j < TRELLIS_STAGES; j++) {
        for (i = 0; i < TRELLIS_STATES; i++) {
            paths[j][i].cost    = INFINITY;
            paths[j][i].prev    = -2;
        }
    }
    idx = 1;
    abs_pow34_v(s->scoefs, sce->coeffs, 1024);
    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
        start = w*128;
        for (g = 0; g < sce->ics.num_swb; g++) {
            const float *coefs = sce->coeffs + start;
            float qmin, qmax;
            int nz = 0;
            bandaddr[idx] = w * 16 + g;
            qmin = INT_MAX;
            qmax = 0.0f;
            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
                FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
                if (band->energy <= band->threshold || band->threshold == 0.0f) {
                    sce->zeroes[(w+w2)*16+g] = 1;
                    continue;
                }
                sce->zeroes[(w+w2)*16+g] = 0;
                nz = 1;
                for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
                    float t = fabsf(coefs[w2*128+i]);
                    if (t > 0.0f)
                        qmin = FFMIN(qmin, t);
                    qmax = FFMAX(qmax, t);
                }
            }
            if (nz) {
                int minscale, maxscale;
                float minrd = INFINITY;
                minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
                maxscale = av_clip_uint8(log2(qmax)*4 +  6 + SCALE_ONE_POS - SCALE_DIV_512);
                minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
                maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
                float maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
                for (q = minscale; q < maxscale; q++) {
                    float dist = 0;
                    int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);
                    for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
                        FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
                        dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
                                                            q + q0, cb, lambda / band->threshold, INFINITY, NULL);
                    }
                    minrd = FFMIN(minrd, dist);
                    for (i = 0; i < q1 - q0; i++) {
                        float cost;
                        cost = paths[idx - 1][i].cost + dist
                               + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
                        if (cost < paths[idx][q].cost) {
                            paths[idx][q].cost    = cost;
                            paths[idx][q].prev    = i;
                        }
                    }
                }
            } else {
                for (q = 0; q < q1 - q0; q++) {
                        paths[idx][q].cost = paths[idx - 1][q].cost + 1;
                        paths[idx][q].prev = q;
                }
            }
            sce->zeroes[w*16+g] = !nz;
            start += sce->ics.swb_sizes[g];
            idx++;
        }
    }
    idx--;
    mincost = paths[idx][0].cost;
    minq    = 0;
    for (i = 1; i < TRELLIS_STATES; i++) {
        if (paths[idx][i].cost < mincost) {
            mincost = paths[idx][i].cost;
            minq = i;
        }
    }
    while (idx) {
        sce->sf_idx[bandaddr[idx]] = minq + q0;
        minq = paths[idx][minq].prev;
        idx--;
    }
    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
        for (g = 0;  g < sce->ics.num_swb; g++)
            for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
                sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
}
['static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,\n                                       SingleChannelElement *sce,\n                                       const float lambda)\n{\n    int q, w, w2, g, start = 0;\n    int i, j;\n    int idx;\n    TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];\n    int bandaddr[TRELLIS_STAGES];\n    int minq;\n    float mincost;\n    float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;\n    int q0, q1, qcnt = 0;\n    for (i = 0; i < 1024; i++) {\n        float t = fabsf(sce->coeffs[i]);\n        if (t > 0.0f) {\n            q0f = FFMIN(q0f, t);\n            q1f = FFMAX(q1f, t);\n            qnrgf += t*t;\n            qcnt++;\n        }\n    }\n    if (!qcnt) {\n        memset(sce->sf_idx, 0, sizeof(sce->sf_idx));\n        memset(sce->zeroes, 1, sizeof(sce->zeroes));\n        return;\n    }\n    q0 = av_clip_uint8(log2(q0f)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);\n    q1 = av_clip_uint8(log2(q1f)*4 +  6 + SCALE_ONE_POS - SCALE_DIV_512);\n    if (q1 - q0 > 60) {\n        int q0low  = q0;\n        int q1high = q1;\n        int qnrg = av_clip_uint8(log2(sqrt(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);\n        q1 = qnrg + 30;\n        q0 = qnrg - 30;\n        if (q0 < q0low) {\n            q1 += q0low - q0;\n            q0  = q0low;\n        } else if (q1 > q1high) {\n            q0 -= q1 - q1high;\n            q1  = q1high;\n        }\n    }\n    for (i = 0; i < TRELLIS_STATES; i++) {\n        paths[0][i].cost    = 0.0f;\n        paths[0][i].prev    = -1;\n    }\n    for (j = 1; j < TRELLIS_STAGES; j++) {\n        for (i = 0; i < TRELLIS_STATES; i++) {\n            paths[j][i].cost    = INFINITY;\n            paths[j][i].prev    = -2;\n        }\n    }\n    idx = 1;\n    abs_pow34_v(s->scoefs, sce->coeffs, 1024);\n    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n        start = w*128;\n        for (g = 0; g < sce->ics.num_swb; g++) {\n            const float *coefs = sce->coeffs + start;\n            float qmin, qmax;\n            int nz = 0;\n            bandaddr[idx] = w * 16 + g;\n            qmin = INT_MAX;\n            qmax = 0.0f;\n            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {\n                FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];\n                if (band->energy <= band->threshold || band->threshold == 0.0f) {\n                    sce->zeroes[(w+w2)*16+g] = 1;\n                    continue;\n                }\n                sce->zeroes[(w+w2)*16+g] = 0;\n                nz = 1;\n                for (i = 0; i < sce->ics.swb_sizes[g]; i++) {\n                    float t = fabsf(coefs[w2*128+i]);\n                    if (t > 0.0f)\n                        qmin = FFMIN(qmin, t);\n                    qmax = FFMAX(qmax, t);\n                }\n            }\n            if (nz) {\n                int minscale, maxscale;\n                float minrd = INFINITY;\n                minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);\n                maxscale = av_clip_uint8(log2(qmax)*4 +  6 + SCALE_ONE_POS - SCALE_DIV_512);\n                minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);\n                maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);\n                float maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);\n                for (q = minscale; q < maxscale; q++) {\n                    float dist = 0;\n                    int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);\n                    for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {\n                        FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];\n                        dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],\n                                                            q + q0, cb, lambda / band->threshold, INFINITY, NULL);\n                    }\n                    minrd = FFMIN(minrd, dist);\n                    for (i = 0; i < q1 - q0; i++) {\n                        float cost;\n                        cost = paths[idx - 1][i].cost + dist\n                               + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];\n                        if (cost < paths[idx][q].cost) {\n                            paths[idx][q].cost    = cost;\n                            paths[idx][q].prev    = i;\n                        }\n                    }\n                }\n            } else {\n                for (q = 0; q < q1 - q0; q++) {\n                        paths[idx][q].cost = paths[idx - 1][q].cost + 1;\n                        paths[idx][q].prev = q;\n                }\n            }\n            sce->zeroes[w*16+g] = !nz;\n            start += sce->ics.swb_sizes[g];\n            idx++;\n        }\n    }\n    idx--;\n    mincost = paths[idx][0].cost;\n    minq    = 0;\n    for (i = 1; i < TRELLIS_STATES; i++) {\n        if (paths[idx][i].cost < mincost) {\n            mincost = paths[idx][i].cost;\n            minq = i;\n        }\n    }\n    while (idx) {\n        sce->sf_idx[bandaddr[idx]] = minq + q0;\n        minq = paths[idx][minq].prev;\n        idx--;\n    }\n    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])\n        for (g = 0;  g < sce->ics.num_swb; g++)\n            for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)\n                sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];\n}']