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

libavcodec/ac3enc.c:2234:1: Parameter `avctx->priv_data->fbw_channels`
2232.  * Initialize the encoder.
2233.  */
2234. static av_cold int ac3_encode_init(AVCodecContext *avctx)
      ^
2235. {
2236.     AC3EncodeContext *s = avctx->priv_data;

libavcodec/ac3enc.c:2243:11: Call
2241.     ff_ac3_common_init();
2242. 
2243.     ret = validate_options(avctx, s);
                ^
2244.     if (ret)
2245.         return ret;

libavcodec/ac3enc.c:2041:1: Parameter `s->fbw_channels`
  2039. 
  2040. 
  2041. static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
        ^
  2042. {
  2043.     int i, ret;

libavcodec/ac3enc.c:2051:11: Call
  2049.                                       "might be incorrect.\n");
  2050.     }
  2051.     ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
                  ^
  2052.     if (ret) {
  2053.         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

libavcodec/ac3enc.c:1994:1: Parameter `s->fbw_channels`
    1992.  * Set channel information during initialization.
    1993.  */
    1994. static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
          ^
    1995.                                     int64_t *channel_layout)
    1996. {

libavcodec/ac3enc.c:2264:5: Call
2262.     }
2263. 
2264.     set_bandwidth(s);
          ^
2265. 
2266.     rematrixing_init(s);

libavcodec/ac3enc.c:2117:1: <Offset trace>
2115.  * default value will be used.
2116.  */
2117. static av_cold void set_bandwidth(AC3EncodeContext *s)
      ^
2118. {
2119.     int ch, bw_code;

libavcodec/ac3enc.c:2117:1: Parameter `s->fbw_channels`
  2115.  * default value will be used.
  2116.  */
  2117. static av_cold void set_bandwidth(AC3EncodeContext *s)
        ^
  2118. {
  2119.     int ch, bw_code;

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

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

libavcodec/ac3enc.c:2128:19: Array access: Offset: [-1+min(0, avctx->priv_data->fbw_channels), -1+max(6, avctx->priv_data->fbw_channels)] Size: 5 by call to `set_bandwidth` 
  2126.     } else {
  2127.         /* use default bandwidth setting */
  2128.         bw_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];
                          ^
  2129.     }
  2130. 

static av_cold void set_bandwidth(AC3EncodeContext *s)
{
    int ch, bw_code;
    if (s->cutoff) {
        int fbw_coeffs;
        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;
        bw_code        = av_clip((fbw_coeffs - 73) / 3, 0, 60);
    } else {
        bw_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];
    }
    for (ch = 0; ch < s->fbw_channels; ch++) {
        s->bandwidth_code[ch] = bw_code;
        s->nb_coefs[ch]       = bw_code * 3 + 73;
    }
    if (s->lfe_on)
        s->nb_coefs[s->lfe_channel] = 7;
}
['static av_cold int ac3_encode_init(AVCodecContext *avctx)\n{\n    AC3EncodeContext *s = avctx->priv_data;\n    int ret, frame_size_58;\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->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];\n    s->bits_written    = 0;\n    s->samples_written = 0;\n    s->frame_size      = s->frame_size_min;\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    set_bandwidth(s);\n    rematrixing_init(s);\n    exponent_init(s);\n    bit_alloc_init(s);\n    ret = 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    ac3_encode_close(avctx);\n    return ret;\n}', 'static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)\n{\n    int i, ret;\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    for (i = 0; i < 9; i++) {\n        if ((ff_ac3_sample_rate_tab[i / 3] >> (i % 3)) == avctx->sample_rate)\n            break;\n    }\n    if (i == 9) {\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       = 8 + s->bit_alloc.sr_shift;\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->bit_rate        = avctx->bit_rate;\n    s->frame_size_code = i << 1;\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    ret = validate_metadata(avctx);\n    if (ret)\n        return ret;\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    if (av_get_channel_layout_nb_channels(ch_layout) != channels)\n        return AVERROR(EINVAL);\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;\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 ch, bw_code;\n    if (s->cutoff) {\n        int fbw_coeffs;\n        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;\n        bw_code        = av_clip((fbw_coeffs - 73) / 3, 0, 60);\n    } else {\n        bw_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];\n    }\n    for (ch = 0; ch < s->fbw_channels; ch++) {\n        s->bandwidth_code[ch] = bw_code;\n        s->nb_coefs[ch]       = bw_code * 3 + 73;\n    }\n    if (s->lfe_on)\n        s->nb_coefs[s->lfe_channel] = 7;\n}']