Add the noreturn attribute on the assert functions to aid static analysis, improve test_repacketizer error handling, and silence 19 clang static analysis errors with additional assertions.

This commit is contained in:
Gregory Maxwell 2011-10-03 21:07:39 -04:00 committed by Jean-Marc Valin
parent 4a7c9859cb
commit 5d5875a93a
15 changed files with 46 additions and 6 deletions

View file

@ -51,6 +51,9 @@
#ifdef ENABLE_ASSERTIONS
#include <stdio.h>
#include <stdlib.h>
#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);

View file

@ -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;

View file

@ -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--)
{

View file

@ -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);

View file

@ -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<n;i++)
xx[i] = x[i];
for (i=0;i<overlap;i++)

View file

@ -450,6 +450,10 @@ void unquant_coarse_energy(const CELTMode *m, int start, int end, opus_val16 *ol
int qi;
opus_val32 q;
opus_val32 tmp;
/* It would be better to express this invariant as a
test on C at function entry, but that isn't enough
to make the static analyzer happy. */
celt_assert(c<2);
tell = ec_tell(dec);
if(budget-tell>=15)
{

View file

@ -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,

View file

@ -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++ ) {

View file

@ -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 ];

View file

@ -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 ];

View file

@ -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 );

View file

@ -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 ] );

View file

@ -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 ) );

View file

@ -85,6 +85,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include <stdio.h>
# include <stdlib.h>
#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);

View file

@ -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);