Skip to content

Commit

Permalink
Silence compiler warnings
Browse files Browse the repository at this point in the history
clang -Wcast-align warnings with ambisonics enabled
clang -Wnull-pointer-arithmetic warnings in test_opus_api.c
gcc -Wimplicit-fallthrough warnings on arm
msvc warning C4244 in celt_encoder.c with fixed point
  • Loading branch information
mark4o committed Jul 22, 2018
1 parent c1c247d commit 01b035f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion celt/celt_encoder.c
Expand Up @@ -1221,7 +1221,7 @@ static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem,
}
#ifndef DISABLE_FLOAT_API
if (analysis->valid)
gain1 *= analysis->max_pitch_ratio;
gain1 = (opus_val16)(gain1 * analysis->max_pitch_ratio);
#else
(void)analysis;
#endif
Expand Down
10 changes: 5 additions & 5 deletions silk/arm/LPC_inv_pred_gain_neon_intr.c
Expand Up @@ -217,13 +217,13 @@ opus_int32 silk_LPC_inverse_pred_gain_neon( /* O Returns inverse predi
{
case 24:
t0_s32x4 = vpadalq_s16( t0_s32x4, t2_s16x8 );
/* Intend to fall through */
/* FALLTHROUGH */

case 16:
t0_s32x4 = vpadalq_s16( t0_s32x4, t1_s16x8 );
vst1q_s32( Atmp_QA + 16, vshll_n_s16( vget_low_s16 ( t2_s16x8 ), QA - 12 ) );
vst1q_s32( Atmp_QA + 20, vshll_n_s16( vget_high_s16( t2_s16x8 ), QA - 12 ) );
/* Intend to fall through */
/* FALLTHROUGH */

case 8:
{
Expand All @@ -246,17 +246,17 @@ opus_int32 silk_LPC_inverse_pred_gain_neon( /* O Returns inverse predi
case 6:
DC_resp += (opus_int32)A_Q12[ 5 ];
DC_resp += (opus_int32)A_Q12[ 4 ];
/* Intend to fall through */
/* FALLTHROUGH */

case 4:
DC_resp += (opus_int32)A_Q12[ 3 ];
DC_resp += (opus_int32)A_Q12[ 2 ];
/* Intend to fall through */
/* FALLTHROUGH */

case 2:
DC_resp += (opus_int32)A_Q12[ 1 ];
DC_resp += (opus_int32)A_Q12[ 0 ];
/* Intend to fall through */
/* FALLTHROUGH */

default:
break;
Expand Down
3 changes: 2 additions & 1 deletion src/mapping_matrix.c
Expand Up @@ -58,7 +58,8 @@ opus_int32 mapping_matrix_get_size(int rows, int cols)

opus_int16 *mapping_matrix_get_data(const MappingMatrix *matrix)
{
return (opus_int16*)((char*)matrix + align(sizeof(MappingMatrix)));
/* void* cast avoids clang -Wcast-align warning */
return (opus_int16*)(void*)((char*)matrix + align(sizeof(MappingMatrix)));
}

void mapping_matrix_init(MappingMatrix * const matrix,
Expand Down
8 changes: 6 additions & 2 deletions src/opus_projection_decoder.c
Expand Up @@ -93,12 +93,16 @@ static void opus_projection_copy_channel_out_short(

static MappingMatrix *get_demixing_matrix(OpusProjectionDecoder *st)
{
return (MappingMatrix*)((char*)st + align(sizeof(OpusProjectionDecoder)));
/* void* cast avoids clang -Wcast-align warning */
return (MappingMatrix*)(void*)((char*)st +
align(sizeof(OpusProjectionDecoder)));
}

static OpusMSDecoder *get_multistream_decoder(OpusProjectionDecoder *st)
{
return (OpusMSDecoder*)((char*)st + align(sizeof(OpusProjectionDecoder) +
/* void* cast avoids clang -Wcast-align warning */
return (OpusMSDecoder*)(void*)((char*)st +
align(sizeof(OpusProjectionDecoder) +
st->demixing_matrix_size_in_bytes));
}

Expand Down
15 changes: 11 additions & 4 deletions src/opus_projection_encoder.c
Expand Up @@ -119,19 +119,26 @@ static int get_streams_from_channels(int channels, int mapping_family,

static MappingMatrix *get_mixing_matrix(OpusProjectionEncoder *st)
{
return (MappingMatrix *)((char*)st + align(sizeof(OpusProjectionEncoder)));
/* void* cast avoids clang -Wcast-align warning */
return (MappingMatrix *)(void*)((char*)st +
align(sizeof(OpusProjectionEncoder)));
}

static MappingMatrix *get_demixing_matrix(OpusProjectionEncoder *st)
{
return (MappingMatrix *)((char*)st + align(sizeof(OpusProjectionEncoder) +
/* void* cast avoids clang -Wcast-align warning */
return (MappingMatrix *)(void*)((char*)st +
align(sizeof(OpusProjectionEncoder) +
st->mixing_matrix_size_in_bytes));
}

static OpusMSEncoder *get_multistream_encoder(OpusProjectionEncoder *st)
{
return (OpusMSEncoder *)((char*)st + align(sizeof(OpusProjectionEncoder) +
st->mixing_matrix_size_in_bytes + st->demixing_matrix_size_in_bytes));
/* void* cast avoids clang -Wcast-align warning */
return (OpusMSEncoder *)(void*)((char*)st +
align(sizeof(OpusProjectionEncoder) +
st->mixing_matrix_size_in_bytes +
st->demixing_matrix_size_in_bytes));
}

opus_int32 opus_projection_ambisonics_encoder_get_size(int channels,
Expand Down
62 changes: 29 additions & 33 deletions tests/test_opus_api.c
Expand Up @@ -78,6 +78,9 @@ void *malloc_hook(__attribute__((unused)) size_t size,
}
#endif

opus_int32 *null_int_ptr = (opus_int32 *)NULL;
opus_uint32 *null_uint_ptr = (opus_uint32 *)NULL;

static const opus_int32 opus_rates[5] = {48000,24000,16000,12000,8000};

opus_int32 test_dec_api(void)
Expand All @@ -92,8 +95,6 @@ opus_int32 test_dec_api(void)
#endif
short sbuf[960*2];
int c,err;
opus_int32 *nullvalue;
nullvalue=0;

cfgs=0;
/*First test invalid configurations which should fail*/
Expand Down Expand Up @@ -147,7 +148,7 @@ opus_int32 test_dec_api(void)
fprintf(stdout," opus_decoder_create() ........................ OK.\n");
fprintf(stdout," opus_decoder_init() .......................... OK.\n");

err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL));
err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(null_uint_ptr));
if(err != OPUS_BAD_ARG)test_failed();
VG_UNDEF(&dec_final_range,sizeof(dec_final_range));
err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
Expand All @@ -161,15 +162,15 @@ opus_int32 test_dec_api(void)
fprintf(stdout," OPUS_UNIMPLEMENTED ........................... OK.\n");
cfgs++;

err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH((opus_int32 *)NULL));
err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH(null_int_ptr));
if(err != OPUS_BAD_ARG)test_failed();
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
if(err != OPUS_OK || i!=0)test_failed();
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");
cfgs++;

err=opus_decoder_ctl(dec, OPUS_GET_SAMPLE_RATE((opus_int32 *)NULL));
err=opus_decoder_ctl(dec, OPUS_GET_SAMPLE_RATE(null_int_ptr));
if(err != OPUS_BAD_ARG)test_failed();
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_SAMPLE_RATE(&i));
Expand All @@ -178,7 +179,7 @@ opus_int32 test_dec_api(void)
cfgs++;

/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
Expand All @@ -202,7 +203,7 @@ opus_int32 test_dec_api(void)
cfgs++;
fprintf(stdout," OPUS_GET_PITCH ............................... OK.\n");

err=opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION((opus_int32 *)NULL));
err=opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(null_int_ptr));
if(err != OPUS_BAD_ARG)test_failed();
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&i));
Expand All @@ -215,7 +216,7 @@ opus_int32 test_dec_api(void)
VG_CHECK(&i,sizeof(i));
if(err != OPUS_OK || i!=0)test_failed();
cfgs++;
err=opus_decoder_ctl(dec, OPUS_GET_GAIN(nullvalue));
err=opus_decoder_ctl(dec, OPUS_GET_GAIN(null_int_ptr));
if(err != OPUS_BAD_ARG)test_failed();
cfgs++;
err=opus_decoder_ctl(dec, OPUS_SET_GAIN(-32769));
Expand Down Expand Up @@ -352,11 +353,6 @@ opus_int32 test_msdec_api(void)
#endif
short sbuf[960*2];
int a,b,c,err;
#if 0
/*Relevant test not enabled for multistream*/
int *nullvalue;
nullvalue=0;
#endif

mapping[0]=0;
mapping[1]=1;
Expand Down Expand Up @@ -610,7 +606,7 @@ opus_int32 test_msdec_api(void)
#if 0
/*Currently unimplemented for multistream*/
/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
Expand Down Expand Up @@ -1166,15 +1162,15 @@ opus_int32 test_enc_api(void)
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
if(err!=OPUS_OK || i<0 || i>32766)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
fprintf(stdout," OPUS_GET_LOOKAHEAD ........................... OK.\n");

err=opus_encoder_ctl(enc,OPUS_GET_SAMPLE_RATE(&i));
if(err!=OPUS_OK || i!=48000)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_SAMPLE_RATE((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_SAMPLE_RATE(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
fprintf(stdout," OPUS_GET_SAMPLE_RATE ......................... OK.\n");
Expand All @@ -1183,15 +1179,15 @@ opus_int32 test_enc_api(void)
fprintf(stdout," OPUS_UNIMPLEMENTED ........................... OK.\n");
cfgs++;

err=opus_encoder_ctl(enc,OPUS_GET_APPLICATION((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_APPLICATION(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_APPLICATION(i),OPUS_GET_APPLICATION(&i),-1,OPUS_AUTO,
OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY,
" OPUS_SET_APPLICATION ......................... OK.\n",
" OPUS_GET_APPLICATION ......................... OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_BITRATE((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_BITRATE(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
if(opus_encoder_ctl(enc,OPUS_SET_BITRATE(1073741832))!=OPUS_OK)test_failed();
Expand All @@ -1205,7 +1201,7 @@ opus_int32 test_enc_api(void)
" OPUS_SET_BITRATE ............................. OK.\n",
" OPUS_GET_BITRATE ............................. OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_FORCE_CHANNELS((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_FORCE_CHANNELS(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_FORCE_CHANNELS(i),OPUS_GET_FORCE_CHANNELS(&i),-1,3,
Expand Down Expand Up @@ -1243,7 +1239,7 @@ opus_int32 test_enc_api(void)
cfgs++;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_BANDWIDTH((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_BANDWIDTH(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");
Expand Down Expand Up @@ -1276,76 +1272,76 @@ opus_int32 test_enc_api(void)
i!=OPUS_BANDWIDTH_MEDIUMBAND&&i!=OPUS_BANDWIDTH_WIDEBAND&&
i!=OPUS_BANDWIDTH_FULLBAND))test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_MAX_BANDWIDTH((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_MAX_BANDWIDTH(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
fprintf(stdout," OPUS_GET_MAX_BANDWIDTH ....................... OK.\n");

err=opus_encoder_ctl(enc,OPUS_GET_DTX((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_DTX(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_DTX(i),OPUS_GET_DTX(&i),-1,2,
1,0,
" OPUS_SET_DTX ................................. OK.\n",
" OPUS_GET_DTX ................................. OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_COMPLEXITY((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_COMPLEXITY(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_COMPLEXITY(i),OPUS_GET_COMPLEXITY(&i),-1,11,
0,10,
" OPUS_SET_COMPLEXITY .......................... OK.\n",
" OPUS_GET_COMPLEXITY .......................... OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_INBAND_FEC((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_INBAND_FEC(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_INBAND_FEC(i),OPUS_GET_INBAND_FEC(&i),-1,2,
1,0,
" OPUS_SET_INBAND_FEC .......................... OK.\n",
" OPUS_GET_INBAND_FEC .......................... OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_PACKET_LOSS_PERC((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_PACKET_LOSS_PERC(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_PACKET_LOSS_PERC(i),OPUS_GET_PACKET_LOSS_PERC(&i),-1,101,
100,0,
" OPUS_SET_PACKET_LOSS_PERC .................... OK.\n",
" OPUS_GET_PACKET_LOSS_PERC .................... OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_VBR((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_VBR(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_VBR(i),OPUS_GET_VBR(&i),-1,2,
1,0,
" OPUS_SET_VBR ................................. OK.\n",
" OPUS_GET_VBR ................................. OK.\n")

/* err=opus_encoder_ctl(enc,OPUS_GET_VOICE_RATIO((opus_int32 *)NULL));
/* err=opus_encoder_ctl(enc,OPUS_GET_VOICE_RATIO(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_VOICE_RATIO(i),OPUS_GET_VOICE_RATIO(&i),-2,101,
0,50,
" OPUS_SET_VOICE_RATIO ......................... OK.\n",
" OPUS_GET_VOICE_RATIO ......................... OK.\n")*/

err=opus_encoder_ctl(enc,OPUS_GET_VBR_CONSTRAINT((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_VBR_CONSTRAINT(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_VBR_CONSTRAINT(i),OPUS_GET_VBR_CONSTRAINT(&i),-1,2,
1,0,
" OPUS_SET_VBR_CONSTRAINT ...................... OK.\n",
" OPUS_GET_VBR_CONSTRAINT ...................... OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_SIGNAL((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_SIGNAL(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_SIGNAL(i),OPUS_GET_SIGNAL(&i),-12345,0x7FFFFFFF,
OPUS_SIGNAL_MUSIC,OPUS_AUTO,
" OPUS_SET_SIGNAL .............................. OK.\n",
" OPUS_GET_SIGNAL .............................. OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_LSB_DEPTH((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_LSB_DEPTH(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_LSB_DEPTH(i),OPUS_GET_LSB_DEPTH(&i),7,25,16,24,
Expand All @@ -1355,14 +1351,14 @@ opus_int32 test_enc_api(void)
err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED(&i));
if(i!=0)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_PREDICTION_DISABLED(i),OPUS_GET_PREDICTION_DISABLED(&i),-1,2,1,0,
" OPUS_SET_PREDICTION_DISABLED ................. OK.\n",
" OPUS_GET_PREDICTION_DISABLED ................. OK.\n")

err=opus_encoder_ctl(enc,OPUS_GET_EXPERT_FRAME_DURATION((opus_int32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_EXPERT_FRAME_DURATION(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_2_5_MS));
Expand Down Expand Up @@ -1399,7 +1395,7 @@ opus_int32 test_enc_api(void)

/*OPUS_SET_FORCE_MODE is not tested here because it's not a public API, however the encoder tests use it*/

err=opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL));
err=opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE(null_uint_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
if(opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
Expand Down

0 comments on commit 01b035f

Please sign in to comment.