Some more coverity issues cleaned up

This commit is contained in:
Steve Underwood 2014-04-30 13:10:59 +08:00
parent dac846cc7e
commit ba6457bbe9
5 changed files with 27 additions and 11 deletions

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

View 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.

View 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

View 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

View 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