shithub: opus

Download patch

ref: 01b035f8ba4f48e9e1ad9f9407f77ce9a7e4aa44
parent: c1c247d7e715100a50ca185948c7336bdd4dfdba
author: Mark Harris <mark.hsj@gmail.com>
date: Sat Jul 21 13:55:24 EDT 2018

Silence compiler warnings

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

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1221,7 +1221,7 @@
    }
 #ifndef DISABLE_FLOAT_API
    if (analysis->valid)
-      gain1 *= analysis->max_pitch_ratio;
+      gain1 = (opus_val16)(gain1 * analysis->max_pitch_ratio);
 #else
    (void)analysis;
 #endif
--- a/silk/arm/LPC_inv_pred_gain_neon_intr.c
+++ b/silk/arm/LPC_inv_pred_gain_neon_intr.c
@@ -217,13 +217,13 @@
         {
         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:
         {
@@ -246,17 +246,17 @@
         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;
--- a/src/mapping_matrix.c
+++ b/src/mapping_matrix.c
@@ -58,7 +58,8 @@
 
 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,
--- a/src/opus_projection_decoder.c
+++ b/src/opus_projection_decoder.c
@@ -93,12 +93,16 @@
 
 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));
 }
 
--- a/src/opus_projection_encoder.c
+++ b/src/opus_projection_encoder.c
@@ -119,19 +119,26 @@
 
 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,
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -78,6 +78,9 @@
 }
 #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)
@@ -92,8 +95,6 @@
 #endif
    short sbuf[960*2];
    int c,err;
-   opus_int32 *nullvalue;
-   nullvalue=0;
 
    cfgs=0;
    /*First test invalid configurations which should fail*/
@@ -147,7 +148,7 @@
    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));
@@ -161,7 +162,7 @@
    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));
@@ -169,7 +170,7 @@
    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));
@@ -178,7 +179,7 @@
    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));
@@ -202,7 +203,7 @@
    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));
@@ -215,7 +216,7 @@
    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));
@@ -352,11 +353,6 @@
 #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;
@@ -610,7 +606,7 @@
 #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));
@@ -1166,7 +1162,7 @@
    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");
@@ -1174,7 +1170,7 @@
    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");
@@ -1183,7 +1179,7 @@
    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,
@@ -1191,7 +1187,7 @@
      "    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();
@@ -1205,7 +1201,7 @@
      "    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,
@@ -1243,7 +1239,7 @@
    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");
@@ -1276,12 +1272,12 @@
       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,
@@ -1289,7 +1285,7 @@
      "    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,
@@ -1297,7 +1293,7 @@
      "    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,
@@ -1305,7 +1301,7 @@
      "    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,
@@ -1313,7 +1309,7 @@
      "    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,
@@ -1321,7 +1317,7 @@
      "    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,
@@ -1329,7 +1325,7 @@
      "    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,
@@ -1337,7 +1333,7 @@
      "    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,
@@ -1345,7 +1341,7 @@
      "    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,
@@ -1355,7 +1351,7 @@
    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,
@@ -1362,7 +1358,7 @@
      "    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));
@@ -1399,7 +1395,7 @@
 
    /*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();