libavcodec/ac3enc.c:2377: error: Buffer Overrun L2
  Offset: [-1+min(0, `avctx->priv_data->fbw_channels`), -1+max(7, `avctx->priv_data->fbw_channels`)] Size: 5 by call to `set_bandwidth`.

libavcodec/ac3enc.c:2321:9: Parameter `avctx->priv_data->fbw_channels`
2319.  * Initialize the encoder.
2320.  */
2321. av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
              ^
2322. {
2323.     AC3EncodeContext *s = avctx->priv_data;

libavcodec/ac3enc.c:2332:11: Call
2330.     ff_ac3_common_init();
2331. 
2332.     ret = validate_options(avctx, s);
                ^
2333.     if (ret)
2334.         return ret;

libavcodec/ac3enc.c:2019:1: Parameter `s->fbw_channels`
  2017. 
  2018. 
  2019. static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
        ^
  2020. {
  2021.     int i, ret, max_sr;

libavcodec/ac3enc.c:2029:11: Call
  2027.                                       "might be incorrect.\n");
  2028.     }
  2029.     ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
                  ^
  2030.     if (ret) {
  2031.         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

libavcodec/ac3enc.c:1974:1: Parameter `s->fbw_channels`
    1972.  * Set channel information during initialization.
    1973.  */
    1974. static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
          ^
    1975.                                     int64_t *channel_layout)
    1976. {

libavcodec/ac3enc.c:2377:5: Call
2375.         s->output_frame_header = ac3_output_frame_header;
2376. 
2377.     set_bandwidth(s);
          ^
2378. 
2379.     exponent_init(s);

libavcodec/ac3enc.c:2145:1: <Offset trace>
2143.  * default value will be used.
2144.  */
2145. static av_cold void set_bandwidth(AC3EncodeContext *s)
      ^
2146. {
2147.     int blk, ch;

libavcodec/ac3enc.c:2145:1: Parameter `s->fbw_channels`
  2143.  * default value will be used.
  2144.  */
  2145. static av_cold void set_bandwidth(AC3EncodeContext *s)
        ^
  2146. {
  2147.     int blk, ch;

libavcodec/ac3enc.c:108:1: <Length trace>
106.  * bandwidth_tab[fbw_channels-1][sample rate code][bit rate code]
107.  */
108. static const uint8_t ac3_bandwidth_tab[5][3][19] = {
     ^
109. //      32  40  48  56  64  80  96 112 128 160 192 224 256 320 384 448 512 576 640
110. 

libavcodec/ac3enc.c:108:1: Array declaration
  106.  * bandwidth_tab[fbw_channels-1][sample rate code][bit rate code]
  107.  */
  108. static const uint8_t ac3_bandwidth_tab[5][3][19] = {
       ^
  109. //      32  40  48  56  64  80  96 112 128 160 192 224 256 320 384 448 512 576 640
  110. 

libavcodec/ac3enc.c:2157:29: Array access: Offset: [-1+min(0, avctx->priv_data->fbw_channels), -1+max(7, avctx->priv_data->fbw_channels)] Size: 5 by call to `set_bandwidth` 
  2155.     } else {
  2156.         /* use default bandwidth setting */
  2157.         s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];
                                    ^
  2158.     }
  2159. 

static av_cold void set_bandwidth(AC3EncodeContext *s)
{
    int blk, ch;
    int av_uninit(cpl_start);
    if (s->cutoff) {
        int fbw_coeffs;
        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;
        s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
    } else {
        s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];
    }
    for (ch = 1; ch <= s->fbw_channels; ch++) {
        s->start_freq[ch] = 0;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73;
    }
    if (s->lfe_on) {
        s->start_freq[s->lfe_channel] = 0;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[ch] = 7;
    }
    if (s->cpl_enabled) {
        if (s->options.cpl_start >= 0) {
            cpl_start = s->options.cpl_start;
        } else {
            cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2];
            if (cpl_start < 0)
                s->cpl_enabled = 0;
        }
    }
    if (s->cpl_enabled) {
        int i, cpl_start_band, cpl_end_band;
        uint8_t *cpl_band_sizes = s->cpl_band_sizes;
        cpl_end_band   = s->bandwidth_code / 4 + 3;
        cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15));
        s->num_cpl_subbands = cpl_end_band - cpl_start_band;
        s->num_cpl_bands = 1;
        *cpl_band_sizes  = 12;
        for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
            if (ff_eac3_default_cpl_band_struct[i]) {
                *cpl_band_sizes += 12;
            } else {
                s->num_cpl_bands++;
                cpl_band_sizes++;
                *cpl_band_sizes = 12;
            }
        }
        s->start_freq[CPL_CH] = cpl_start_band * 12 + 37;
        s->cpl_end_freq       = cpl_end_band   * 12 + 37;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq;
    }
}
['int ff_ac3_encode_init(AVCodecContext *avctx)\n{\n    AC3EncodeContext *s = avctx->priv_data;\n    int ret, frame_size_58;\n    s->eac3 = avctx->codec_id == CODEC_ID_EAC3;\n    avctx->frame_size = AC3_FRAME_SIZE;\n    ff_ac3_common_init();\n    ret = validate_options(avctx, s);\n    if (ret)\n        return ret;\n    s->bitstream_mode = avctx->audio_service_type;\n    if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)\n        s->bitstream_mode = 0x7;\n    s->bits_written    = 0;\n    s->samples_written = 0;\n    frame_size_58 = (( s->frame_size    >> 2) + ( s->frame_size    >> 4)) << 1;\n    s->crc_inv[0] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);\n    if (s->bit_alloc.sr_code == 1) {\n        frame_size_58 = (((s->frame_size+2) >> 2) + ((s->frame_size+2) >> 4)) << 1;\n        s->crc_inv[1] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);\n    }\n    if (CONFIG_AC3_FIXED_ENCODER && s->fixed_point) {\n        s->mdct_end                     = ff_ac3_fixed_mdct_end;\n        s->mdct_init                    = ff_ac3_fixed_mdct_init;\n        s->apply_window                 = ff_ac3_fixed_apply_window;\n        s->normalize_samples            = ff_ac3_fixed_normalize_samples;\n        s->scale_coefficients           = ff_ac3_fixed_scale_coefficients;\n        s->deinterleave_input_samples   = ff_ac3_fixed_deinterleave_input_samples;\n        s->apply_mdct                   = ff_ac3_fixed_apply_mdct;\n        s->apply_channel_coupling       = ff_ac3_fixed_apply_channel_coupling;\n        s->compute_rematrixing_strategy = ff_ac3_fixed_compute_rematrixing_strategy;\n    } else if (CONFIG_AC3_ENCODER || CONFIG_EAC3_ENCODER) {\n        s->mdct_end                     = ff_ac3_float_mdct_end;\n        s->mdct_init                    = ff_ac3_float_mdct_init;\n        s->apply_window                 = ff_ac3_float_apply_window;\n        s->scale_coefficients           = ff_ac3_float_scale_coefficients;\n        s->deinterleave_input_samples   = ff_ac3_float_deinterleave_input_samples;\n        s->apply_mdct                   = ff_ac3_float_apply_mdct;\n        s->apply_channel_coupling       = ff_ac3_float_apply_channel_coupling;\n        s->compute_rematrixing_strategy = ff_ac3_float_compute_rematrixing_strategy;\n    }\n    if (CONFIG_EAC3_ENCODER && s->eac3)\n        s->output_frame_header = ff_eac3_output_frame_header;\n    else\n        s->output_frame_header = ac3_output_frame_header;\n    set_bandwidth(s);\n    exponent_init(s);\n    bit_alloc_init(s);\n    FF_ALLOCZ_OR_GOTO(avctx, s->mdct, sizeof(AC3MDCTContext), init_fail);\n    ret = s->mdct_init(avctx, s->mdct, 9);\n    if (ret)\n        goto init_fail;\n    ret = allocate_buffers(avctx);\n    if (ret)\n        goto init_fail;\n    avctx->coded_frame= avcodec_alloc_frame();\n    dsputil_init(&s->dsp, avctx);\n    ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);\n    dprint_options(avctx);\n    return 0;\ninit_fail:\n    ff_ac3_encode_close(avctx);\n    return ret;\n}', 'static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)\n{\n    int i, ret, max_sr;\n    if (!avctx->channel_layout) {\n        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "\n                                      "encoder will guess the layout, but it "\n                                      "might be incorrect.\\n");\n    }\n    ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);\n    if (ret) {\n        av_log(avctx, AV_LOG_ERROR, "invalid channel layout\\n");\n        return ret;\n    }\n    max_sr = s->eac3 ? 2 : 8;\n    for (i = 0; i <= max_sr; i++) {\n        if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate)\n            break;\n    }\n    if (i > max_sr) {\n        av_log(avctx, AV_LOG_ERROR, "invalid sample rate\\n");\n        return AVERROR(EINVAL);\n    }\n    s->sample_rate        = avctx->sample_rate;\n    s->bit_alloc.sr_shift = i / 3;\n    s->bit_alloc.sr_code  = i % 3;\n    s->bitstream_id       = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;\n    if (s->eac3) {\n        int max_br, min_br, wpf, min_br_dist, min_br_code;\n        max_br = 2048 * s->sample_rate / AC3_FRAME_SIZE * 16;\n        min_br = ((s->sample_rate + (AC3_FRAME_SIZE-1)) / AC3_FRAME_SIZE) * 16;\n        if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) {\n            av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d "\n                   "for this sample rate\\n", min_br, max_br);\n            return AVERROR(EINVAL);\n        }\n        wpf = (avctx->bit_rate / 16) * AC3_FRAME_SIZE / s->sample_rate;\n        av_assert1(wpf > 0 && wpf <= 2048);\n        min_br_code = -1;\n        min_br_dist = INT_MAX;\n        for (i = 0; i < 19; i++) {\n            int br_dist = abs(ff_ac3_bitrate_tab[i] * 1000 - avctx->bit_rate);\n            if (br_dist < min_br_dist) {\n                min_br_dist = br_dist;\n                min_br_code = i;\n            }\n        }\n        s->frame_size_code = min_br_code << 1;\n        while (wpf > 1 && wpf * s->sample_rate / AC3_FRAME_SIZE * 16 > avctx->bit_rate)\n            wpf--;\n        s->frame_size_min = 2 * wpf;\n    } else {\n        for (i = 0; i < 19; i++) {\n            if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)\n                break;\n        }\n        if (i == 19) {\n            av_log(avctx, AV_LOG_ERROR, "invalid bit rate\\n");\n            return AVERROR(EINVAL);\n        }\n        s->frame_size_code = i << 1;\n        s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];\n    }\n    s->bit_rate   = avctx->bit_rate;\n    s->frame_size = s->frame_size_min;\n    if (avctx->cutoff < 0) {\n        av_log(avctx, AV_LOG_ERROR, "invalid cutoff frequency\\n");\n        return AVERROR(EINVAL);\n    }\n    s->cutoff = avctx->cutoff;\n    if (s->cutoff > (s->sample_rate >> 1))\n        s->cutoff = s->sample_rate >> 1;\n    if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&\n         avctx->channels == 1) ||\n        ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||\n          avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY  ||\n          avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)\n         && avctx->channels > 1)) {\n        av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "\n                                    "specified number of channels\\n");\n        return AVERROR(EINVAL);\n    }\n    if (!s->eac3) {\n        ret = validate_metadata(avctx);\n        if (ret)\n            return ret;\n    }\n    s->rematrixing_enabled = s->options.stereo_rematrixing &&\n                             (s->channel_mode == AC3_CHMODE_STEREO);\n    s->cpl_enabled = s->options.channel_coupling &&\n                     s->channel_mode >= AC3_CHMODE_STEREO && !s->fixed_point;\n    return 0;\n}', 'static av_cold int set_channel_info(AC3EncodeContext *s, int channels,\n                                    int64_t *channel_layout)\n{\n    int ch_layout;\n    if (channels < 1 || channels > AC3_MAX_CHANNELS)\n        return AVERROR(EINVAL);\n    if ((uint64_t)*channel_layout > 0x7FF)\n        return AVERROR(EINVAL);\n    ch_layout = *channel_layout;\n    if (!ch_layout)\n        ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL);\n    s->lfe_on       = !!(ch_layout & AV_CH_LOW_FREQUENCY);\n    s->channels     = channels;\n    s->fbw_channels = channels - s->lfe_on;\n    s->lfe_channel  = s->lfe_on ? s->fbw_channels + 1 : -1;\n    if (s->lfe_on)\n        ch_layout -= AV_CH_LOW_FREQUENCY;\n    switch (ch_layout) {\n    case AV_CH_LAYOUT_MONO:           s->channel_mode = AC3_CHMODE_MONO;   break;\n    case AV_CH_LAYOUT_STEREO:         s->channel_mode = AC3_CHMODE_STEREO; break;\n    case AV_CH_LAYOUT_SURROUND:       s->channel_mode = AC3_CHMODE_3F;     break;\n    case AV_CH_LAYOUT_2_1:            s->channel_mode = AC3_CHMODE_2F1R;   break;\n    case AV_CH_LAYOUT_4POINT0:        s->channel_mode = AC3_CHMODE_3F1R;   break;\n    case AV_CH_LAYOUT_QUAD:\n    case AV_CH_LAYOUT_2_2:            s->channel_mode = AC3_CHMODE_2F2R;   break;\n    case AV_CH_LAYOUT_5POINT0:\n    case AV_CH_LAYOUT_5POINT0_BACK:   s->channel_mode = AC3_CHMODE_3F2R;   break;\n    default:\n        return AVERROR(EINVAL);\n    }\n    s->has_center   = (s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO;\n    s->has_surround =  s->channel_mode & 0x04;\n    s->channel_map  = ff_ac3_enc_channel_map[s->channel_mode][s->lfe_on];\n    *channel_layout = ch_layout;\n    if (s->lfe_on)\n        *channel_layout |= AV_CH_LOW_FREQUENCY;\n    return 0;\n}', 'static av_cold void set_bandwidth(AC3EncodeContext *s)\n{\n    int blk, ch;\n    int av_uninit(cpl_start);\n    if (s->cutoff) {\n        int fbw_coeffs;\n        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;\n        s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);\n    } else {\n        s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];\n    }\n    for (ch = 1; ch <= s->fbw_channels; ch++) {\n        s->start_freq[ch] = 0;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73;\n    }\n    if (s->lfe_on) {\n        s->start_freq[s->lfe_channel] = 0;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[ch] = 7;\n    }\n    if (s->cpl_enabled) {\n        if (s->options.cpl_start >= 0) {\n            cpl_start = s->options.cpl_start;\n        } else {\n            cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2];\n            if (cpl_start < 0)\n                s->cpl_enabled = 0;\n        }\n    }\n    if (s->cpl_enabled) {\n        int i, cpl_start_band, cpl_end_band;\n        uint8_t *cpl_band_sizes = s->cpl_band_sizes;\n        cpl_end_band   = s->bandwidth_code / 4 + 3;\n        cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15));\n        s->num_cpl_subbands = cpl_end_band - cpl_start_band;\n        s->num_cpl_bands = 1;\n        *cpl_band_sizes  = 12;\n        for (i = cpl_start_band + 1; i < cpl_end_band; i++) {\n            if (ff_eac3_default_cpl_band_struct[i]) {\n                *cpl_band_sizes += 12;\n            } else {\n                s->num_cpl_bands++;\n                cpl_band_sizes++;\n                *cpl_band_sizes = 12;\n            }\n        }\n        s->start_freq[CPL_CH] = cpl_start_band * 12 + 37;\n        s->cpl_end_freq       = cpl_end_band   * 12 + 37;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq;\n    }\n}']