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

libavcodec/ac3enc.c:2967:1: Parameter `avctx->priv_data->channels`
2965.  * Initialize the encoder.
2966.  */
2967. static av_cold int ac3_encode_init(AVCodecContext *avctx)
      ^
2968. {
2969.     AC3EncodeContext *s = avctx->priv_data;

libavcodec/ac3enc.c:2978:11: Call
2976.     ff_ac3_common_init();
2977. 
2978.     ret = validate_options(avctx, s);
                ^
2979.     if (ret)
2980.         return ret;

libavcodec/ac3enc.c:2663:1: Parameter `s->channels`
  2661. 
  2662. 
  2663. static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s)
        ^
  2664. {
  2665.     int i, ret, max_sr;

libavcodec/ac3enc.c:2673:11: Call
  2671.                                       "might be incorrect.\n");
  2672.     }
  2673.     ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
                  ^
  2674.     if (ret) {
  2675.         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

libavcodec/ac3enc.c:2618:1: Parameter `s->channels`
    2616.  * Set channel information during initialization.
    2617.  */
    2618. static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
          ^
    2619.                                     int64_t *channel_layout)
    2620. {

libavcodec/ac3enc.c:3001:5: Call
2999.     exponent_init(s);
3000. 
3001.     bit_alloc_init(s);
          ^
3002. 
3003.     ret = mdct_init(avctx, &s->mdct, 9);

libavcodec/ac3enc.c:1271:1: <Offset trace>
1269.  * Set default parameter codes and calculate parameter values.
1270.  */
1271. static void bit_alloc_init(AC3EncodeContext *s)
      ^
1272. {
1273.     int ch;

libavcodec/ac3enc.c:1271:1: Parameter `s->channels`
  1269.  * Set default parameter codes and calculate parameter values.
  1270.  */
  1271. static void bit_alloc_init(AC3EncodeContext *s)
        ^
  1272. {
  1273.     int ch;

libavcodec/ac3enc.c:1271:1: <Length trace>
1269.  * Set default parameter codes and calculate parameter values.
1270.  */
1271. static void bit_alloc_init(AC3EncodeContext *s)
      ^
1272. {
1273.     int ch;

libavcodec/ac3enc.c:1271:1: Parameter `s->fast_gain_code[*]`
  1269.  * Set default parameter codes and calculate parameter values.
  1270.  */
  1271. static void bit_alloc_init(AC3EncodeContext *s)
        ^
  1272. {
  1273.     int ch;

libavcodec/ac3enc.c:1282:9: Array access: Offset: [0, max(7, avctx->priv_data->channels)] Size: 7 by call to `bit_alloc_init` 
  1280.     s->floor_code      = 7;
  1281.     for (ch = 0; ch <= s->channels; ch++)
  1282.         s->fast_gain_code[ch] = 4;
                ^
  1283. 
  1284.     /* 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 = s->eac3 ? 2 : 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    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    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, 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 &&\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 = s->eac3 ? 2 : 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}']