libavcodec/ac3enc.c:2788: error: Buffer Overrun L2
  Offset: [0, max(7, `avctx->priv_data->channels`)] Size: 7 by call to `bit_alloc_init`.

libavcodec/ac3enc.c:2754:1: Parameter `avctx->priv_data->channels`
2752.  * Initialize the encoder.
2753.  */
2754. static av_cold int ac3_encode_init(AVCodecContext *avctx)
      ^
2755. {
2756.     AC3EncodeContext *s = avctx->priv_data;

libavcodec/ac3enc.c:2763:11: Call
2761.     ff_ac3_common_init();
2762. 
2763.     ret = validate_options(avctx, s);
                ^
2764.     if (ret)
2765.         return ret;

libavcodec/ac3enc.c:2494:1: Parameter `s->channels`
  2492. 
  2493. 
  2494. static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
        ^
  2495. {
  2496.     int i, ret;

libavcodec/ac3enc.c:2504:11: Call
  2502.                                       "might be incorrect.\n");
  2503.     }
  2504.     ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
                  ^
  2505.     if (ret) {
  2506.         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

libavcodec/ac3enc.c:2449:1: Parameter `s->channels`
    2447.  * Set channel information during initialization.
    2448.  */
    2449. static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
          ^
    2450.                                     int64_t *channel_layout)
    2451. {

libavcodec/ac3enc.c:2788:5: Call
2786.     exponent_init(s);
2787. 
2788.     bit_alloc_init(s);
          ^
2789. 
2790.     ret = mdct_init(avctx, &s->mdct, 9);

libavcodec/ac3enc.c:1245:1: <Offset trace>
1243.  * Set default parameter codes and calculate parameter values.
1244.  */
1245. static void bit_alloc_init(AC3EncodeContext *s)
      ^
1246. {
1247.     int ch;

libavcodec/ac3enc.c:1245:1: Parameter `s->channels`
  1243.  * Set default parameter codes and calculate parameter values.
  1244.  */
  1245. static void bit_alloc_init(AC3EncodeContext *s)
        ^
  1246. {
  1247.     int ch;

libavcodec/ac3enc.c:1245:1: <Length trace>
1243.  * Set default parameter codes and calculate parameter values.
1244.  */
1245. static void bit_alloc_init(AC3EncodeContext *s)
      ^
1246. {
1247.     int ch;

libavcodec/ac3enc.c:1245:1: Parameter `s->fast_gain_code[*]`
  1243.  * Set default parameter codes and calculate parameter values.
  1244.  */
  1245. static void bit_alloc_init(AC3EncodeContext *s)
        ^
  1246. {
  1247.     int ch;

libavcodec/ac3enc.c:1256:9: Array access: Offset: [0, max(7, avctx->priv_data->channels)] Size: 7 by call to `bit_alloc_init` 
  1254.     s->floor_code      = 7;
  1255.     for (ch = 0; ch <= s->channels; ch++)
  1256.         s->fast_gain_code[ch] = 4;
                ^
  1257. 
  1258.     /* initial snr offset */

static void bit_alloc_init(AC3EncodeContext *s)
{
    int ch;
    s->slow_decay_code = 2;
    s->fast_decay_code = 1;
    s->slow_gain_code  = 1;
    s->db_per_bit_code = 3;
    s->floor_code      = 7;
    for (ch = 0; ch <= s->channels; ch++)
        s->fast_gain_code[ch] = 4;
    s->coarse_snr_offset = 40;
    s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->bit_alloc.sr_shift;
    s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->bit_alloc.sr_shift;
    s->bit_alloc.slow_gain  = ff_ac3_slow_gain_tab[s->slow_gain_code];
    s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
    s->bit_alloc.floor      = ff_ac3_floor_tab[s->floor_code];
    s->bit_alloc.cpl_fast_leak = 0;
    s->bit_alloc.cpl_slow_leak = 0;
    count_frame_bits_fixed(s);
}
['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    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    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 &&\n                     CONFIG_AC3ENC_FLOAT;\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 void bit_alloc_init(AC3EncodeContext *s)\n{\n    int ch;\n    s->slow_decay_code = 2;\n    s->fast_decay_code = 1;\n    s->slow_gain_code  = 1;\n    s->db_per_bit_code = 3;\n    s->floor_code      = 7;\n    for (ch = 0; ch <= s->channels; ch++)\n        s->fast_gain_code[ch] = 4;\n    s->coarse_snr_offset = 40;\n    s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->bit_alloc.sr_shift;\n    s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->bit_alloc.sr_shift;\n    s->bit_alloc.slow_gain  = ff_ac3_slow_gain_tab[s->slow_gain_code];\n    s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];\n    s->bit_alloc.floor      = ff_ac3_floor_tab[s->floor_code];\n    s->bit_alloc.cpl_fast_leak = 0;\n    s->bit_alloc.cpl_slow_leak = 0;\n    count_frame_bits_fixed(s);\n}']