diff --git a/celt/arch.h b/celt/arch.h index 08286e94..7bd82777 100644 --- a/celt/arch.h +++ b/celt/arch.h @@ -51,6 +51,9 @@ #ifdef ENABLE_ASSERTIONS #include #include +#ifdef __GNUC__ +__attribute__((noreturn)) +#endif static inline void _celt_fatal(const char *str, const char *file, int line) { fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); diff --git a/celt/bands.c b/celt/bands.c index b8a27044..666863fc 100644 --- a/celt/bands.c +++ b/celt/bands.c @@ -403,6 +403,8 @@ int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int decision; int hf_sum=0; + celt_assert(end>0); + N0 = M*m->shortMdctSize; if (M*(eBands[end]-eBands[end-1]) <= 8) @@ -457,6 +459,7 @@ int spreading_decision(const CELTMode *m, celt_norm *X, int *average, *tapset_decision=0; } /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ + celt_assert(nbBands>0); /*M*(eBands[end]-eBands[end-1]) <= 8 assures this*/ sum /= nbBands; /* Recursive averaging */ sum = (sum+*average)>>1; @@ -545,6 +548,7 @@ static void deinterleave_hadamard(celt_norm *X, int N0, int stride, int hadamard SAVE_STACK; N = N0*stride; ALLOC(tmp, N, celt_norm); + celt_assert(stride>0); if (hadamard) { const int *ordery = ordery_table+stride-2; diff --git a/celt/kiss_fft.c b/celt/kiss_fft.c index e9af132c..b14f66b9 100644 --- a/celt/kiss_fft.c +++ b/celt/kiss_fft.c @@ -641,7 +641,6 @@ void opus_fft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fou fstride[L+1] = fstride[L]*p; L++; } while(m!=1); - m2 = 1; m = st->factors[2*L-1]; for (i=L-1;i>=0;i--) { @@ -694,7 +693,6 @@ void opus_ifft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fo fstride[L+1] = fstride[L]*p; L++; } while(m!=1); - m2 = 1; m = st->factors[2*L-1]; for (i=L-1;i>=0;i--) { diff --git a/celt/pitch.c b/celt/pitch.c index f6a97f9b..30c43c56 100644 --- a/celt/pitch.c +++ b/celt/pitch.c @@ -166,6 +166,8 @@ void pitch_search(const opus_val16 * restrict x_lp, opus_val16 * restrict y, SAVE_STACK; + celt_assert(len>0); + celt_assert(max_pitch>0); lag = len+max_pitch; ALLOC(x_lp4, len>>2, opus_val16); diff --git a/celt/plc.c b/celt/plc.c index c9a407ca..2687bf3b 100644 --- a/celt/plc.c +++ b/celt/plc.c @@ -150,6 +150,8 @@ void _celt_autocorr( VARDECL(opus_val16, xx); SAVE_STACK; ALLOC(xx, n, opus_val16); + celt_assert(n>0); + celt_assert(overlap>=0); for (i=0;i=15) { diff --git a/celt/tests/ectest.c b/celt/tests/ectest.c index ee4fc5a0..29a82fcf 100644 --- a/celt/tests/ectest.c +++ b/celt/tests/ectest.c @@ -170,7 +170,6 @@ int main(int _argc,char **_argv){ ec_range_bytes(&enc), (tell_bits+7)/8,seed); ret=-1; } - tell_bits -= 8*ec_range_bytes(&enc); ec_dec_init(&dec,ptr,DATA_SIZE2); if(ec_tell_frac(&dec)!=tell[0]){ fprintf(stderr, diff --git a/silk/NLSF2A.c b/silk/NLSF2A.c index 87b87498..eca855b7 100644 --- a/silk/NLSF2A.c +++ b/silk/NLSF2A.c @@ -77,6 +77,7 @@ void silk_NLSF2A( opus_int32 maxabs, absval, idx=0, sc_Q16, invGain_Q30; silk_assert( LSF_COS_TAB_SZ_FIX == 128 ); + silk_assert( d==6||d==8||d==10||d==12||d==14||d==16 ); /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */ for( k = 0; k < d; k++ ) { diff --git a/silk/NSQ_del_dec.c b/silk/NSQ_del_dec.c index f2d3c7c1..52295caf 100644 --- a/silk/NSQ_del_dec.c +++ b/silk/NSQ_del_dec.c @@ -335,6 +335,8 @@ static inline void silk_noise_shape_quantizer_del_dec( NSQ_del_dec_struct *psDD; NSQ_sample_struct *psSS; + silk_assert( nStatesDelayedDecision > 0 ); + shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; diff --git a/silk/float/schur_FLP.c b/silk/float/schur_FLP.c index 0f123698..59921bb7 100644 --- a/silk/float/schur_FLP.c +++ b/silk/float/schur_FLP.c @@ -41,6 +41,8 @@ silk_float silk_schur_FLP( /* O returns residual energy silk_float C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; silk_float Ctmp1, Ctmp2, rc_tmp; + silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); + /* Copy correlations */ for( k = 0; k < order+1; k++ ) { C[ k ][ 0 ] = C[ k ][ 1 ] = auto_corr[ k ]; diff --git a/silk/pitch_analysis_core.c b/silk/pitch_analysis_core.c index c8ce79b1..70438474 100644 --- a/silk/pitch_analysis_core.c +++ b/silk/pitch_analysis_core.c @@ -182,8 +182,6 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 silk_assert( basis_ptr >= frame_4kHz ); silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz ); - normalizer = 0; - cross_corr = 0; /* Calculate first vector products before loop */ cross_corr = silk_inner_prod_aligned( target_ptr, basis_ptr, sf_length_8kHz ); normalizer = silk_inner_prod_aligned( basis_ptr, basis_ptr, sf_length_8kHz ); diff --git a/silk/schur.c b/silk/schur.c index 8f4e700e..86f37345 100644 --- a/silk/schur.c +++ b/silk/schur.c @@ -43,6 +43,8 @@ opus_int32 silk_schur( /* O: Returns residual energ opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; opus_int32 Ctmp1, Ctmp2, rc_tmp_Q15; + silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); + /* Get number of leading zeros */ lz = silk_CLZ32( c[ 0 ] ); diff --git a/silk/schur64.c b/silk/schur64.c index 5ee04b45..8c9ee057 100644 --- a/silk/schur64.c +++ b/silk/schur64.c @@ -43,6 +43,8 @@ opus_int32 silk_schur64( /* O: Returns residual ener opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; opus_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31; + silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); + /* Check for invalid input */ if( c[ 0 ] <= 0 ) { silk_memset( rc_Q16, 0, order * sizeof( opus_int32 ) ); diff --git a/silk/typedef.h b/silk/typedef.h index f546d378..26fea652 100644 --- a/silk/typedef.h +++ b/silk/typedef.h @@ -85,6 +85,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # include # include #define silk_fatal(str) _silk_fatal(str, __FILE__, __LINE__); +#ifdef __GNUC__ +__attribute__((noreturn)) +#endif static inline void _silk_fatal(const char *str, const char *file, int line) { fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); diff --git a/src/test_repacketizer.c b/src/test_repacketizer.c index 6ab25d96..6554c8cb 100644 --- a/src/test_repacketizer.c +++ b/src/test_repacketizer.c @@ -47,6 +47,11 @@ int main(int argc, char *argv[]) if (strcmp(argv[i], "-merge")==0) { merge = atoi(argv[i+1]); + if(merge<1) + { + fprintf(stderr, "-merge parameter must be at least 1.\n"); + return 1; + } i++; } else if (strcmp(argv[i], "-split")==0) split = 1; @@ -58,7 +63,17 @@ int main(int argc, char *argv[]) } } fin = fopen(argv[argc-2], "r"); + if(fin==NULL) + { + fprintf(stderr, "Error opening input file: %s\n", argv[argc-2]); + return 1; + } fout = fopen(argv[argc-1], "w"); + if(fout==NULL) + { + fprintf(stderr, "Error opening output file: %s\n", argv[argc-1]); + return 1; + } rp = opus_repacketizer_create(); while (!eof) @@ -75,9 +90,12 @@ int main(int argc, char *argv[]) if (len[i]>1500 || len[i]<0) { if (feof(fin)) + { eof = 1; - else + } else { fprintf(stderr, "Invalid payload length\n"); + return 1; + } break; } err = fread(ch, 1, 4, fin);