From dd7b0dac3ba85cda7e314eaa867b4f0d716c9ac4 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sat, 29 Jun 2013 20:06:07 -0700 Subject: Fixes some return without va_end in the api, adds tests. Also makes the CTL bad argument handling more consistent to avoid mistakes like that in the future. Also updates the variable duration docs. --- src/opus_decoder.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/opus_decoder.c') diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 6bc70919..13a910f4 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -937,12 +937,14 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) case OPUS_GET_BANDWIDTH_REQUEST: { opus_int32 *value = va_arg(ap, opus_int32*); + if (!value) goto bad_arg; *value = st->bandwidth; } break; case OPUS_GET_FINAL_RANGE_REQUEST: { opus_uint32 *value = va_arg(ap, opus_uint32*); + if (!value) goto bad_arg; *value = st->rangeFinal; } break; @@ -961,22 +963,14 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) case OPUS_GET_SAMPLE_RATE_REQUEST: { opus_int32 *value = va_arg(ap, opus_int32*); - if (value==NULL) - { - ret = OPUS_BAD_ARG; - break; - } + if (!value) goto bad_arg; *value = st->Fs; } break; case OPUS_GET_PITCH_REQUEST: { opus_int32 *value = va_arg(ap, opus_int32*); - if (value==NULL) - { - ret = OPUS_BAD_ARG; - break; - } + if (!value) goto bad_arg; if (st->prev_mode == MODE_CELT_ONLY) celt_decoder_ctl(celt_dec, OPUS_GET_PITCH(value)); else @@ -986,28 +980,21 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) case OPUS_GET_GAIN_REQUEST: { opus_int32 *value = va_arg(ap, opus_int32*); - if (value==NULL) - { - ret = OPUS_BAD_ARG; - break; - } + if (!value) goto bad_arg; *value = st->decode_gain; } break; case OPUS_SET_GAIN_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); - if (value<-32768 || value>32767) - { - ret = OPUS_BAD_ARG; - break; - } + if (value<-32768 || value>32767) goto bad_arg; st->decode_gain = value; } break; case OPUS_GET_LAST_PACKET_DURATION_REQUEST: { opus_uint32 *value = va_arg(ap, opus_uint32*); + if (!value) goto bad_arg; *value = st->last_packet_duration; } break; @@ -1019,6 +1006,9 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) va_end(ap); return ret; +bad_arg: + va_end(ap); + return OPUS_BAD_ARG; } void opus_decoder_destroy(OpusDecoder *st) -- cgit v1.2.3