On Fri, Dec 2, 2011 at 2:20 PM, Nathan Caldwell <[email protected]> wrote: > Macroify sanity checks and check return value of allocs. > --- > libavcodec/aacenc.c | 37 ++++++++++++++++++------------------- > 1 files changed, 18 insertions(+), 19 deletions(-) > > diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c > index b112fa8..64e6e20 100644 > --- a/libavcodec/aacenc.c > +++ b/libavcodec/aacenc.c > @@ -46,6 +46,12 @@ > > #define AAC_MAX_CHANNELS 6 > > +#define RETURN_ON_ERROR( cond, ... ) \ > +if (cond) { \ > + av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ > + return -1; \ > +} > + > static const uint8_t swb_size_1024_96[] = { > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, > 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, > @@ -173,22 +179,12 @@ static av_cold int aac_encode_init(AVCodecContext > *avctx) > for (i = 0; i < 16; i++) > if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) > break; > - if (i == 16) { > - av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", > avctx->sample_rate); > - return -1; > - } > - if (avctx->channels > AAC_MAX_CHANNELS) { > - av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", > avctx->channels); > - return -1; > - } > - if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != > FF_PROFILE_AAC_LOW) { > - av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", > avctx->profile); > - return -1; > - } > - if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * > avctx->channels) { > - av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); > - return -1; > - } > + > + RETURN_ON_ERROR(i == 16, "Unsupported sample rate %d\n", > avctx->sample_rate); > + RETURN_ON_ERROR(avctx->channels > AAC_MAX_CHANNELS, "Unsupported number > of channels: %d\n", avctx->channels); > + RETURN_ON_ERROR(avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile > != FF_PROFILE_AAC_LOW, "Unsupported profile %d\n", avctx->profile); > + RETURN_ON_ERROR(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * > avctx->channels, "Too many bits per frame requested\n"); > +
These guys should probably be given "real" return codes. > s->samplerate_index = i; > > dsputil_init(&s->dsp, avctx); > @@ -201,9 +197,10 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) > ff_init_ff_sine_windows(7); > > s->chan_map = aac_chan_configs[avctx->channels-1]; > - s->samples = av_malloc(2 * 1024 * avctx->channels * > sizeof(s->samples[0])); > - s->cpe = av_mallocz(sizeof(ChannelElement) * > s->chan_map[0]); > - avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE); > + FF_ALLOC_OR_GOTO (avctx, s->samples, 2 * 1024 * avctx->channels * > sizeof(s->samples[0]), fail); > + FF_ALLOCZ_OR_GOTO(avctx, s->cpe, sizeof(ChannelElement) * > s->chan_map[0], fail); > + FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 + > FF_INPUT_BUFFER_PADDING_SIZE, fail); > + > avctx->extradata_size = 5; > put_audio_specific_config(avctx); > > @@ -222,6 +219,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) > ff_aac_tableinit(); > > return 0; > +fail: > + return AVERROR(ENOMEM); > } > Seems reasonable. _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
