From 1617f65eecbd894b17870929a9ffec4d62078d89 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Tue, 11 Sep 2012 14:06:27 +0000 Subject: [PATCH] Coverity warnings in audio codecs Coverity reported errors/warnings in iSAC and iLBC. Seven of the warnings should be fixed with this CL. Review URL: https://webrtc-codereview.appspot.com/793004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2740 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/modules/audio_coding/codecs/ilbc/cb_search.c | 3 ++- .../codecs/isac/fix/source/bandwidth_estimator.c | 6 ++++-- .../codecs/isac/fix/source/entropy_coding.c | 2 +- .../audio_coding/codecs/isac/fix/source/isacfix.c | 14 -------------- .../codecs/isac/main/source/entropy_coding.c | 2 +- .../audio_coding/codecs/isac/main/source/fft.c | 4 ---- 6 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/modules/audio_coding/codecs/ilbc/cb_search.c b/src/modules/audio_coding/codecs/ilbc/cb_search.c index c51ccf7cbe..551a9a27eb 100644 --- a/src/modules/audio_coding/codecs/ilbc/cb_search.c +++ b/src/modules/audio_coding/codecs/ilbc/cb_search.c @@ -69,7 +69,8 @@ void WebRtcIlbcfix_CbSearch( WebRtc_Word32 cDot[128]; WebRtc_Word32 Crit[128]; WebRtc_Word16 targetVec[SUBL+LPC_FILTERORDER]; - WebRtc_Word16 cbvectors[CB_MEML]; + WebRtc_Word16 cbvectors[CB_MEML + 1]; /* Adding one extra position for + Coverity warnings. */ WebRtc_Word16 codedVec[SUBL]; WebRtc_Word16 interpSamples[20*4]; WebRtc_Word16 interpSamplesFilt[20*4]; diff --git a/src/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c b/src/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c index a274b6671e..8e21b29e67 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c +++ b/src/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c @@ -630,8 +630,10 @@ WebRtc_UWord16 WebRtcIsacfix_GetDownlinkBwIndexImpl(BwEstimatorstr *bweStr) WEBRTC_SPL_UMUL(102, WEBRTC_SPL_LSHIFT_U32((WebRtc_UWord32)rate + bweStr->recHeaderRate, 5)); bweStr->recBwAvg = WEBRTC_SPL_RSHIFT_U32(bweStr->recBwAvg, 10); - /* find quantization index that gives the closest rate after averaging */ - for (rateInd = 1; rateInd < 12; rateInd++) { + /* Find quantization index that gives the closest rate after averaging. + * Note that we don't need to check the last value, rate <= kQRateTable[11], + * because we will use rateInd = 11 even if rate > kQRateTable[11]. */ + for (rateInd = 1; rateInd < 11; rateInd++) { if (rate <= kQRateTable[rateInd]){ break; } diff --git a/src/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c b/src/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c index 0b64d8358b..03fccac0d1 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c +++ b/src/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c @@ -1589,7 +1589,7 @@ int WebRtcIsacfix_DecodePitchGain(Bitstr_dec *streamdata, WebRtc_Word16 *PitchGa *pitch_gain_cdf_ptr = WebRtcIsacfix_kPitchGainCdf; err = WebRtcIsacfix_DecHistBisectMulti(&index_comb, streamdata, pitch_gain_cdf_ptr, WebRtcIsacfix_kCdfTableSizeGain, 1); /* error check, Q_mean_Gain.. tables are of size 144 */ - if ((err<0) || (index_comb<0) || (index_comb>144)) + if ((err < 0) || (index_comb < 0) || (index_comb >= 144)) return -ISAC_RANGE_ERROR_DECODE_PITCH_GAIN; /* unquantize back to pitch gains by table look-up */ diff --git a/src/modules/audio_coding/codecs/isac/fix/source/isacfix.c b/src/modules/audio_coding/codecs/isac/fix/source/isacfix.c index 02e18e3ff5..890cd279b9 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/isacfix.c +++ b/src/modules/audio_coding/codecs/isac/fix/source/isacfix.c @@ -614,13 +614,6 @@ WebRtc_Word16 WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst memcpy(streamdata.stream, encoded, 5); #endif - if (packet_size == 0) - { - /* return error code if the packet length is null */ - ISAC_inst->errorcode = ISAC_EMPTY_PACKET; - return -1; - } - err = WebRtcIsacfix_EstimateBandwidth(&ISAC_inst->bwestimator_obj, &streamdata, packet_size, @@ -709,13 +702,6 @@ WebRtc_Word16 WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst, memcpy(streamdata.stream, encoded, 5); #endif - if (packet_size == 0) - { - /* return error code if the packet length is null */ - ISAC_inst->errorcode = ISAC_EMPTY_PACKET; - return -1; - } - err = WebRtcIsacfix_EstimateBandwidth(&ISAC_inst->bwestimator_obj, &streamdata, packet_size, diff --git a/src/modules/audio_coding/codecs/isac/main/source/entropy_coding.c b/src/modules/audio_coding/codecs/isac/main/source/entropy_coding.c index 49c695ce2f..0ef1b38ce5 100644 --- a/src/modules/audio_coding/codecs/isac/main/source/entropy_coding.c +++ b/src/modules/audio_coding/codecs/isac/main/source/entropy_coding.c @@ -1518,7 +1518,7 @@ int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, WebRtcIsac_kQPitchGainCdf_ptr, WebRtcIsac_kQCdfTableSizeGain, 1); /* Error check, Q_mean_Gain.. tables are of size 144 */ - if ((err < 0) || (index_comb < 0) || (index_comb > 144)) { + if ((err < 0) || (index_comb < 0) || (index_comb >= 144)) { return -ISAC_RANGE_ERROR_DECODE_PITCH_GAIN; } /* De-quantize back to pitch gains by table look-up. */ diff --git a/src/modules/audio_coding/codecs/isac/main/source/fft.c b/src/modules/audio_coding/codecs/isac/main/source/fft.c index c8247983aa..c854d8c27c 100644 --- a/src/modules/audio_coding/codecs/isac/main/source/fft.c +++ b/src/modules/audio_coding/codecs/isac/main/source/fft.c @@ -335,10 +335,6 @@ static int FFTRADIX (REAL Re[], /* allow full use of alloc'd space */ max_perm = fftstate->MaxPermAlloced; } - if (fftstate->Tmp0 == NULL || fftstate->Tmp1 == NULL || fftstate->Tmp2 == NULL || fftstate->Tmp3 == NULL - || fftstate->Perm == NULL) { - return -1; - } /* assign pointers */ Rtmp = (REAL *) fftstate->Tmp0;