]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Some more coverity issues cleaned up
authorSteve Underwood <steveu@coppice.org>
Wed, 30 Apr 2014 05:10:59 +0000 (13:10 +0800)
committerSteve Underwood <steveu@coppice.org>
Wed, 30 Apr 2014 05:10:59 +0000 (13:10 +0800)
libs/spandsp/src/lpc10_encdecs.h
libs/spandsp/src/v17rx.c
libs/spandsp/src/v22bis_rx.c
libs/spandsp/src/v27ter_rx.c
libs/spandsp/src/v29rx.c

index 621b15a83a59f2920081d17562c4aa930d19474b..05dd87f118085f780ce48209d4b5784c75aabc0a 100644 (file)
@@ -78,7 +78,7 @@ static __inline__ int32_t pow_ii(int32_t x, int32_t n)
         if (n == 0  ||  x == 1)
             return 1;
         if (x != -1)
-            return (x == 0)  ?  1/x  :  0;
+            return (x != 0)  ?  1/x  :  0;
         n = -n;
     }
     u = n;
index 4b61af1409c63a57e61f8ac82165b06f66f0368f..6372c5bb584bb0a05cc513f42ac14472e7ef4753 100644 (file)
@@ -1252,6 +1252,7 @@ SPAN_DECLARE_NONSTD(int) v17_rx(v17_rx_state_t *s, const int16_t amp[], int len)
     complexf_t sample;
     float v;
 #endif
+    int32_t root_power;
     int32_t power;
 
     for (i = 0;  i < len;  i++)
@@ -1309,11 +1310,15 @@ SPAN_DECLARE_NONSTD(int) v17_rx(v17_rx_state_t *s, const int16_t amp[], int len)
         {
             /* Only AGC until we have locked down the setting. */
             if (s->agc_scaling_save == FP_SCALE(0.0f))
+            {
+                if ((root_power = fixed_sqrt32(power)) == 0)
+                    root_power = 1;
 #if defined(SPANDSP_USE_FIXED_POINTx)
-                s->agc_scaling = saturate16(((int32_t) (FP_SCALE(2.17f)*1024.0f))/fixed_sqrt32(power));
+                s->agc_scaling = saturate16(((int32_t) (FP_SCALE(2.17f)*1024.0f))/root_power);
 #else
-                s->agc_scaling = (FP_SCALE(2.17f)/RX_PULSESHAPER_GAIN)/sqrtf(power);
+                s->agc_scaling = (FP_SCALE(2.17f)/RX_PULSESHAPER_GAIN)/root_power;
 #endif
+            }
             /* Pulse shape while still at the carrier frequency, using a quadrature
                pair of filters. This results in a properly bandpass filtered complex
                signal, which can be brought directly to baseband by complex mixing.
index aba3dd2980da84eacb35a0f998cd3ff79566712a..64d21480134e54018c7ee7bb052ebd7d74952959 100644 (file)
@@ -799,6 +799,7 @@ SPAN_DECLARE_NONSTD(int) v22bis_rx(v22bis_state_t *s, const int16_t amp[], int l
     float ii;
     float qq;
 #endif
+    int32_t root_power;
     int32_t power;
 
     for (i = 0;  i < len;  i++)
@@ -860,10 +861,12 @@ SPAN_DECLARE_NONSTD(int) v22bis_rx(v22bis_state_t *s, const int16_t amp[], int l
             if (s->rx.training == V22BIS_RX_TRAINING_STAGE_SYMBOL_ACQUISITION)
             {
                 /* Only AGC during the initial symbol acquisition, and then lock the gain. */
+                if ((root_power = fixed_sqrt32(power)) == 0)
+                    root_power = 1;
 #if defined(SPANDSP_USE_FIXED_POINT)
-                s->rx.agc_scaling = saturate16(((int32_t) (FP_SCALE(0.18f)*FP_SCALE(3.60f)))/fixed_sqrt32(power));
+                s->rx.agc_scaling = saturate16(((int32_t) (FP_SCALE(0.18f)*FP_SCALE(3.60f)))/root_power);
 #else
-                s->rx.agc_scaling = FP_SCALE(0.18f)*FP_SCALE(3.60f)/fixed_sqrt32(power);
+                s->rx.agc_scaling = FP_SCALE(0.18f)*FP_SCALE(3.60f)/root_power;
 #endif
             }
             /* Pulse shape while still at the carrier frequency, using a quadrature
index 3451d660265a49a31bb2d3b91f93336856e78314..d00c779c7f967d582ddbe97f017ee5f41dace3f6 100644 (file)
@@ -834,6 +834,7 @@ SPAN_DECLARE_NONSTD(int) v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], in
     complexf_t sample;
     float v;
 #endif
+    int32_t root_power;
     int32_t power;
 
     if (s->bit_rate == 4800)
@@ -858,10 +859,12 @@ SPAN_DECLARE_NONSTD(int) v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], in
                 if (s->training_stage == TRAINING_STAGE_SYMBOL_ACQUISITION)
                 {
                     /* Only AGC during the initial training */
+                    if ((root_power = fixed_sqrt32(power)) == 0)
+                        root_power = 1;
 #if defined(SPANDSP_USE_FIXED_POINT)
-                    s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.414f)*1024.0f))/fixed_sqrt32(power));
+                    s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.414f)*1024.0f))/root_power);
 #else
-                    s->agc_scaling = (FP_SCALE(1.414f)/RX_PULSESHAPER_4800_GAIN)/fixed_sqrt32(power);
+                    s->agc_scaling = (FP_SCALE(1.414f)/RX_PULSESHAPER_4800_GAIN)/root_power;
 #endif
                 }
                 /* Pulse shape while still at the carrier frequency, using a quadrature
@@ -920,10 +923,12 @@ SPAN_DECLARE_NONSTD(int) v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], in
                 if (s->training_stage == TRAINING_STAGE_SYMBOL_ACQUISITION)
                 {
                     /* Only AGC during the initial training */
+                    if ((root_power = fixed_sqrt32(power)) == 0)
+                        root_power = 1;
 #if defined(SPANDSP_USE_FIXED_POINT)
-                    s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.414f)*1024.0f))/fixed_sqrt32(power));
+                    s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.414f)*1024.0f))/root_power);
 #else
-                    s->agc_scaling = (FP_SCALE(1.414f)/RX_PULSESHAPER_2400_GAIN)/fixed_sqrt32(power);
+                    s->agc_scaling = (FP_SCALE(1.414f)/RX_PULSESHAPER_2400_GAIN)/root_power;
 #endif
                 }
                 /* Pulse shape while still at the carrier frequency, using a quadrature
index 8431ffbfd7017bad191b2595b1e772ca60c151e9..9f37644de16ddb6e37c7439c889c9297617d4d44 100644 (file)
@@ -908,6 +908,7 @@ SPAN_DECLARE_NONSTD(int) v29_rx(v29_rx_state_t *s, const int16_t amp[], int len)
     complexf_t sample;
     float v;
 #endif
+    int32_t root_power;
     int32_t power;
 
     for (i = 0;  i < len;  i++)
@@ -970,10 +971,12 @@ SPAN_DECLARE_NONSTD(int) v29_rx(v29_rx_state_t *s, const int16_t amp[], int len)
             /* Only AGC until we have locked down the setting. */
             if (s->agc_scaling_save == FP_SCALE(0.0f))
             {
+                if ((root_power = fixed_sqrt32(power)) == 0)
+                    root_power = 1;
 #if defined(SPANDSP_USE_FIXED_POINT)
-                s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.25f)*1024.0f))/fixed_sqrt32(power));
+                s->agc_scaling = saturate16(((int32_t) (FP_SCALE(1.25f)*1024.0f))/root_power);
 #else
-                s->agc_scaling = (FP_SCALE(1.25f)/RX_PULSESHAPER_GAIN)/fixed_sqrt32(power);
+                s->agc_scaling = (FP_SCALE(1.25f)/RX_PULSESHAPER_GAIN)/root_power;
 #endif
             }
             /* Pulse shape while still at the carrier frequency, using a quadrature