libavcodec/aacsbr.c:1021: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `sbr_make_f_derived`.

libavcodec/aacsbr.c:1019:11: Call
1017. {
1018.     int err;
1019.     err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params);
                ^
1020.     if (err >= 0)
1021.         err = sbr_make_f_derived(ac, sbr);

libavcodec/aacsbr.c:300:1: Parameter `sbr->k[*]`
  298. 
  299. /// Master Frequency Band Table (14496-3 sp04 p194)
  300. static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr,
       ^
  301.                              SpectrumParameters *spectrum)
  302. {

libavcodec/aacsbr.c:1021:15: Call
1019.     err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params);
1020.     if (err >= 0)
1021.         err = sbr_make_f_derived(ac, sbr);
                    ^
1022.     if (err < 0) {
1023.         av_log(ac->avctx, AV_LOG_ERROR,

libavcodec/aacsbr.c:539:1: Parameter `sbr->k[*]`
  537. 
  538. /// Derived Frequency Band Tables (14496-3 sp04 p197)
  539. static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr)
       ^
  540. {
  541.     int k, temp;

libavcodec/aacsbr.c:581:9: Call
  579.     }
  580. 
  581.     if (sbr_hf_calc_npatches(ac, sbr) < 0)
               ^
  582.         return -1;
  583. 

libavcodec/aacsbr.c:488:1: <LHS trace>
486. 
487. /// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
488. static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr)
     ^
489. {
490.     int i, k, sb = 0;

libavcodec/aacsbr.c:488:1: Parameter `sbr->f_master[*]`
    486. 
    487. /// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
    488. static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr)
         ^
    489. {
    490.     int i, k, sb = 0;

libavcodec/aacsbr.c:504:31: Binary operation: ([0, +oo] - 1):unsigned32 by call to `sbr_make_f_derived` 
    502.     do {
    503.         int odd = 0;
    504.         for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {
                                       ^
    505.             sb = sbr->f_master[i];
    506.             odd = (sb + sbr->k[0]) & 1;

static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr)
{
    int i, k, sb = 0;
    int msb = sbr->k[0];
    int usb = sbr->kx[1];
    int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
    sbr->num_patches = 0;
    if (goal_sb < sbr->kx[1] + sbr->m[1]) {
        for (k = 0; sbr->f_master[k] < goal_sb; k++) ;
    } else
        k = sbr->n_master;
    do {
        int odd = 0;
        for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {
            sb = sbr->f_master[i];
            odd = (sb + sbr->k[0]) & 1;
        }
        if (sbr->num_patches > 5) {
            av_log(ac->avctx, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches);
            return -1;
        }
        sbr->patch_num_subbands[sbr->num_patches]  = FFMAX(sb - usb, 0);
        sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches];
        if (sbr->patch_num_subbands[sbr->num_patches] > 0) {
            usb = sb;
            msb = sb;
            sbr->num_patches++;
        } else
            msb = sbr->kx[1];
        if (sbr->f_master[k] - sb < 3)
            k = sbr->n_master;
    } while (sb != sbr->kx[1] + sbr->m[1]);
    if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1)
        sbr->num_patches--;
    return 0;
}
['static void sbr_reset(AACContext *ac, SpectralBandReplication *sbr)\n{\n    int err;\n    err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params);\n    if (err >= 0)\n        err = sbr_make_f_derived(ac, sbr);\n    if (err < 0) {\n        av_log(ac->avctx, AV_LOG_ERROR,\n               "SBR reset failed. Switching SBR to pure upsampling mode.\\n");\n        sbr->start = 0;\n    }\n}', 'static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr,\n                             SpectrumParameters *spectrum)\n{\n    unsigned int temp, max_qmf_subbands;\n    unsigned int start_min, stop_min;\n    int k;\n    const int8_t *sbr_offset_ptr;\n    int16_t stop_dk[13];\n    if (sbr->sample_rate < 32000) {\n        temp = 3000;\n    } else if (sbr->sample_rate < 64000) {\n        temp = 4000;\n    } else\n        temp = 5000;\n    start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate;\n    stop_min  = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate;\n    switch (sbr->sample_rate) {\n    case 16000:\n        sbr_offset_ptr = sbr_offset[0];\n        break;\n    case 22050:\n        sbr_offset_ptr = sbr_offset[1];\n        break;\n    case 24000:\n        sbr_offset_ptr = sbr_offset[2];\n        break;\n    case 32000:\n        sbr_offset_ptr = sbr_offset[3];\n        break;\n    case 44100: case 48000: case 64000:\n        sbr_offset_ptr = sbr_offset[4];\n        break;\n    case 88200: case 96000: case 128000: case 176400: case 192000:\n        sbr_offset_ptr = sbr_offset[5];\n        break;\n    default:\n        av_log(ac->avctx, AV_LOG_ERROR,\n               "Unsupported sample rate for SBR: %d\\n", sbr->sample_rate);\n        return -1;\n    }\n    sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq];\n    if (spectrum->bs_stop_freq < 14) {\n        sbr->k[2] = stop_min;\n        make_bands(stop_dk, stop_min, 64, 13);\n        qsort(stop_dk, 13, sizeof(stop_dk[0]), qsort_comparison_function_int16);\n        for (k = 0; k < spectrum->bs_stop_freq; k++)\n            sbr->k[2] += stop_dk[k];\n    } else if (spectrum->bs_stop_freq == 14) {\n        sbr->k[2] = 2*sbr->k[0];\n    } else if (spectrum->bs_stop_freq == 15) {\n        sbr->k[2] = 3*sbr->k[0];\n    } else {\n        av_log(ac->avctx, AV_LOG_ERROR,\n               "Invalid bs_stop_freq: %d\\n", spectrum->bs_stop_freq);\n        return -1;\n    }\n    sbr->k[2] = FFMIN(64, sbr->k[2]);\n    if (sbr->sample_rate <= 32000) {\n        max_qmf_subbands = 48;\n    } else if (sbr->sample_rate == 44100) {\n        max_qmf_subbands = 35;\n    } else if (sbr->sample_rate >= 48000)\n        max_qmf_subbands = 32;\n    if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) {\n        av_log(ac->avctx, AV_LOG_ERROR,\n               "Invalid bitstream, too many QMF subbands: %d\\n", sbr->k[2] - sbr->k[0]);\n        return -1;\n    }\n    if (!spectrum->bs_freq_scale) {\n        unsigned int dk;\n        int k2diff;\n        dk = spectrum->bs_alter_scale + 1;\n        sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1;\n        if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))\n            return -1;\n        for (k = 1; k <= sbr->n_master; k++)\n            sbr->f_master[k] = dk;\n        k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk;\n        if (k2diff < 0) {\n            sbr->f_master[1]--;\n            sbr->f_master[2]-= (k2diff < 1);\n        } else if (k2diff) {\n            sbr->f_master[sbr->n_master]++;\n        }\n        sbr->f_master[0] = sbr->k[0];\n        for (k = 1; k <= sbr->n_master; k++)\n            sbr->f_master[k] += sbr->f_master[k - 1];\n    } else {\n        int half_bands = 7 - spectrum->bs_freq_scale;\n        int two_regions, num_bands_0;\n        int vdk0_max, vdk1_min;\n        int16_t vk0[49];\n        if (49 * sbr->k[2] > 110 * sbr->k[0]) {\n            two_regions = 1;\n            sbr->k[1] = 2 * sbr->k[0];\n        } else {\n            two_regions = 0;\n            sbr->k[1] = sbr->k[2];\n        }\n        num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2;\n        if (num_bands_0 <= 0) {\n            av_log(ac->avctx, AV_LOG_ERROR, "Invalid num_bands_0: %d\\n", num_bands_0);\n            return -1;\n        }\n        vk0[0] = 0;\n        make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0);\n        qsort(vk0 + 1, num_bands_0, sizeof(vk0[1]), qsort_comparison_function_int16);\n        vdk0_max = vk0[num_bands_0];\n        vk0[0] = sbr->k[0];\n        for (k = 1; k <= num_bands_0; k++) {\n            if (vk0[k] <= 0) {\n                av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\\n", k, vk0[k]);\n                return -1;\n            }\n            vk0[k] += vk0[k-1];\n        }\n        if (two_regions) {\n            int16_t vk1[49];\n            float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f\n                                                     : 1.0f;\n            int num_bands_1 = lrintf(half_bands * invwarp *\n                                     log2f(sbr->k[2] / (float)sbr->k[1])) * 2;\n            make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1);\n            vdk1_min = array_min_int16(vk1 + 1, num_bands_1);\n            if (vdk1_min < vdk0_max) {\n                int change;\n                qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16);\n                change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1);\n                vk1[1]           += change;\n                vk1[num_bands_1] -= change;\n            }\n            qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16);\n            vk1[0] = sbr->k[1];\n            for (k = 1; k <= num_bands_1; k++) {\n                if (vk1[k] <= 0) {\n                    av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\\n", k, vk1[k]);\n                    return -1;\n                }\n                vk1[k] += vk1[k-1];\n            }\n            sbr->n_master = num_bands_0 + num_bands_1;\n            if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))\n                return -1;\n            memcpy(&sbr->f_master[0],               vk0,\n                   (num_bands_0 + 1) * sizeof(sbr->f_master[0]));\n            memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1,\n                    num_bands_1      * sizeof(sbr->f_master[0]));\n        } else {\n            sbr->n_master = num_bands_0;\n            if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))\n                return -1;\n            memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0]));\n        }\n    }\n    return 0;\n}', 'static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr)\n{\n    int k, temp;\n    sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band;\n    sbr->n[0] = (sbr->n[1] + 1) >> 1;\n    memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band],\n           (sbr->n[1] + 1) * sizeof(sbr->f_master[0]));\n    sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0];\n    sbr->kx[1] = sbr->f_tablehigh[0];\n    if (sbr->kx[1] + sbr->m[1] > 64) {\n        av_log(ac->avctx, AV_LOG_ERROR,\n               "Stop frequency border too high: %d\\n", sbr->kx[1] + sbr->m[1]);\n        return -1;\n    }\n    if (sbr->kx[1] > 32) {\n        av_log(ac->avctx, AV_LOG_ERROR, "Start frequency border too high: %d\\n", sbr->kx[1]);\n        return -1;\n    }\n    sbr->f_tablelow[0] = sbr->f_tablehigh[0];\n    temp = sbr->n[1] & 1;\n    for (k = 1; k <= sbr->n[0]; k++)\n        sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp];\n    sbr->n_q = FFMAX(1, lrintf(sbr->spectrum_params.bs_noise_bands *\n                               log2f(sbr->k[2] / (float)sbr->kx[1])));\n    if (sbr->n_q > 5) {\n        av_log(ac->avctx, AV_LOG_ERROR, "Too many noise floor scale factors: %d\\n", sbr->n_q);\n        return -1;\n    }\n    sbr->f_tablenoise[0] = sbr->f_tablelow[0];\n    temp = 0;\n    for (k = 1; k <= sbr->n_q; k++) {\n        temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k);\n        sbr->f_tablenoise[k] = sbr->f_tablelow[temp];\n    }\n    if (sbr_hf_calc_npatches(ac, sbr) < 0)\n        return -1;\n    sbr_make_f_tablelim(sbr);\n    sbr->data[0].f_indexnoise = 0;\n    sbr->data[1].f_indexnoise = 0;\n    return 0;\n}', 'static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr)\n{\n    int i, k, sb = 0;\n    int msb = sbr->k[0];\n    int usb = sbr->kx[1];\n    int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate;\n    sbr->num_patches = 0;\n    if (goal_sb < sbr->kx[1] + sbr->m[1]) {\n        for (k = 0; sbr->f_master[k] < goal_sb; k++) ;\n    } else\n        k = sbr->n_master;\n    do {\n        int odd = 0;\n        for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {\n            sb = sbr->f_master[i];\n            odd = (sb + sbr->k[0]) & 1;\n        }\n        if (sbr->num_patches > 5) {\n            av_log(ac->avctx, AV_LOG_ERROR, "Too many patches: %d\\n", sbr->num_patches);\n            return -1;\n        }\n        sbr->patch_num_subbands[sbr->num_patches]  = FFMAX(sb - usb, 0);\n        sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches];\n        if (sbr->patch_num_subbands[sbr->num_patches] > 0) {\n            usb = sb;\n            msb = sb;\n            sbr->num_patches++;\n        } else\n            msb = sbr->kx[1];\n        if (sbr->f_master[k] - sb < 3)\n            k = sbr->n_master;\n    } while (sb != sbr->kx[1] + sbr->m[1]);\n    if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1)\n        sbr->num_patches--;\n    return 0;\n}']