More fixes for Coverity issues

This commit is contained in:
Steve Underwood 2014-07-22 10:51:42 +08:00
parent fb6ecb4c76
commit 3b8bc35bd9
6 changed files with 53 additions and 26 deletions

View File

@ -28,7 +28,7 @@
struct super_tone_tx_step_s struct super_tone_tx_step_s
{ {
tone_gen_tone_descriptor_t tone[4]; tone_gen_tone_descriptor_t tone[SUPER_TONE_TX_MAX_TONES];
int tone_on; int tone_on;
int length; int length;
int cycles; int cycles;
@ -38,12 +38,12 @@ struct super_tone_tx_step_s
struct super_tone_tx_state_s struct super_tone_tx_state_s
{ {
tone_gen_tone_descriptor_t tone[4]; tone_gen_tone_descriptor_t tone[SUPER_TONE_TX_MAX_TONES];
uint32_t phase[4]; uint32_t phase[SUPER_TONE_TX_MAX_TONES];
int current_position; int current_position;
int level; int level;
super_tone_tx_step_t *levels[4]; super_tone_tx_step_t *levels[SUPER_TONE_TX_MAX_LEVELS];
int cycles[4]; int cycles[SUPER_TONE_TX_MAX_LEVELS];
}; };
#endif #endif

View File

@ -39,6 +39,9 @@ complex cadence patterns.
*/ */
#define SUPER_TONE_TX_MAX_LEVELS 4
#define SUPER_TONE_TX_MAX_TONES 4
typedef struct super_tone_tx_step_s super_tone_tx_step_t; typedef struct super_tone_tx_step_s super_tone_tx_step_t;
typedef struct super_tone_tx_state_s super_tone_tx_state_t; typedef struct super_tone_tx_state_s super_tone_tx_state_t;

View File

@ -49,6 +49,24 @@ static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n)
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
static __inline__ void vec_movei(int z[], const int x[], int n)
{
memmove(z, x, n*sizeof(z[0]));
}
/*- End of function --------------------------------------------------------*/
static __inline__ void vec_movei16(int16_t z[], const int16_t x[], int n)
{
memmove(z, x, n*sizeof(z[0]));
}
/*- End of function --------------------------------------------------------*/
static __inline__ void vec_movei32(int32_t z[], const int32_t x[], int n)
{
memmove(z, x, n*sizeof(z[0]));
}
/*- End of function --------------------------------------------------------*/
static __inline__ void vec_zeroi(int z[], int n) static __inline__ void vec_zeroi(int z[], int n)
{ {
memset(z, 0, n*sizeof(z[0])); memset(z, 0, n*sizeof(z[0]));

View File

@ -170,7 +170,7 @@ SPAN_DECLARE(int) super_tone_tx(super_tone_tx_state_t *s, int16_t amp[], int max
float xamp; float xamp;
super_tone_tx_step_t *tree; super_tone_tx_step_t *tree;
if (s->level < 0 || s->level > 3) if (s->level < 0 || s->level >= SUPER_TONE_TX_MAX_LEVELS)
return 0; return 0;
samples = 0; samples = 0;
tree = s->levels[s->level]; tree = s->levels[s->level];
@ -182,7 +182,7 @@ SPAN_DECLARE(int) super_tone_tx(super_tone_tx_state_t *s, int16_t amp[], int max
if (s->current_position == 0) if (s->current_position == 0)
{ {
/* New step - prepare the tone generator */ /* New step - prepare the tone generator */
for (i = 0; i < 4; i++) for (i = 0; i < SUPER_TONE_TX_MAX_TONES; i++)
s->tone[i] = tree->tone[i]; s->tone[i] = tree->tone[i];
} }
len = tree->length - s->current_position; len = tree->length - s->current_position;
@ -216,7 +216,7 @@ SPAN_DECLARE(int) super_tone_tx(super_tone_tx_state_t *s, int16_t amp[], int max
for (limit = len + samples; samples < limit; samples++) for (limit = len + samples; samples < limit; samples++)
{ {
xamp = 0.0f; xamp = 0.0f;
for (i = 0; i < 4; i++) for (i = 0; i < SUPER_TONE_TX_MAX_TONES; i++)
{ {
if (s->tone[i].phase_rate == 0) if (s->tone[i].phase_rate == 0)
break; break;
@ -251,9 +251,14 @@ SPAN_DECLARE(int) super_tone_tx(super_tone_tx_state_t *s, int16_t amp[], int max
/* Nesting has priority... */ /* Nesting has priority... */
if (tree->nest) if (tree->nest)
{ {
tree = tree->nest; if (s->level < SUPER_TONE_TX_MAX_LEVELS - 1)
s->levels[++s->level] = tree; {
s->cycles[s->level] = tree->cycles; /* TODO: We have stopped an over-range value being used, but we really
ought to deal with the condition properly. */
tree = tree->nest;
s->levels[++s->level] = tree;
s->cycles[s->level] = tree->cycles;
}
} }
else else
{ {

View File

@ -52,8 +52,9 @@
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h" #include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/time_scale.h" #include "spandsp/vector_int.h"
#include "spandsp/saturated.h" #include "spandsp/saturated.h"
#include "spandsp/time_scale.h"
#include "spandsp/private/time_scale.h" #include "spandsp/private/time_scale.h"
@ -190,46 +191,46 @@ SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[],
if (s->fill + len < s->buf_len) if (s->fill + len < s->buf_len)
{ {
/* Cannot continue without more samples */ /* Cannot continue without more samples */
memcpy(&s->buf[s->fill], in, sizeof(int16_t)*len); vec_copyi16(&s->buf[s->fill], in, len);
s->fill += len; s->fill += len;
return out_len; return out_len;
} }
k = s->buf_len - s->fill; k = s->buf_len - s->fill;
memcpy(&s->buf[s->fill], in, sizeof(int16_t)*k); vec_copyi16(&s->buf[s->fill], in, k);
in_len += k; in_len += k;
s->fill = s->buf_len; s->fill = s->buf_len;
while (s->fill == s->buf_len) while (s->fill == s->buf_len)
{ {
while (s->lcp >= s->buf_len) while (s->lcp >= s->buf_len)
{ {
memcpy(&out[out_len], s->buf, sizeof(int16_t)*s->buf_len); vec_copyi16(&out[out_len], s->buf, s->buf_len);
out_len += s->buf_len; out_len += s->buf_len;
if (len - in_len < s->buf_len) if (len - in_len < s->buf_len)
{ {
/* Cannot continue without more samples */ /* Cannot continue without more samples */
memcpy(s->buf, &in[in_len], sizeof(int16_t)*(len - in_len)); vec_copyi16(s->buf, &in[in_len], len - in_len);
s->fill = len - in_len; s->fill = len - in_len;
s->lcp -= s->buf_len; s->lcp -= s->buf_len;
return out_len; return out_len;
} }
memcpy(s->buf, &in[in_len], sizeof(int16_t)*s->buf_len); vec_copyi16(s->buf, &in[in_len], s->buf_len);
in_len += s->buf_len; in_len += s->buf_len;
s->lcp -= s->buf_len; s->lcp -= s->buf_len;
} }
if (s->lcp > 0) if (s->lcp > 0)
{ {
memcpy(&out[out_len], s->buf, sizeof(int16_t)*s->lcp); vec_copyi16(&out[out_len], s->buf, s->lcp);
out_len += s->lcp; out_len += s->lcp;
memmove(s->buf, &s->buf[s->lcp], sizeof(int16_t)*(s->buf_len - s->lcp)); vec_movei16(s->buf, &s->buf[s->lcp], s->buf_len - s->lcp);
if (len - in_len < s->lcp) if (len - in_len < s->lcp)
{ {
/* Cannot continue without more samples */ /* Cannot continue without more samples */
memcpy(&s->buf[s->buf_len - s->lcp], &in[in_len], sizeof(int16_t)*(len - in_len)); vec_copyi16(&s->buf[s->buf_len - s->lcp], &in[in_len], len - in_len);
s->fill = s->buf_len - s->lcp + len - in_len; s->fill = s->buf_len - s->lcp + len - in_len;
s->lcp = 0; s->lcp = 0;
return out_len; return out_len;
} }
memcpy(&s->buf[s->buf_len - s->lcp], &in[in_len], sizeof(int16_t)*s->lcp); vec_copyi16(&s->buf[s->buf_len - s->lcp], &in[in_len], s->lcp);
in_len += s->lcp; in_len += s->lcp;
s->lcp = 0; s->lcp = 0;
} }
@ -259,21 +260,21 @@ SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[],
{ {
/* Speed up - drop a chunk of data */ /* Speed up - drop a chunk of data */
overlap_add(s->buf, &s->buf[pitch], pitch); overlap_add(s->buf, &s->buf[pitch], pitch);
memcpy(&s->buf[pitch], &s->buf[2*pitch], sizeof(int16_t)*(s->buf_len - 2*pitch)); vec_copyi16(&s->buf[pitch], &s->buf[2*pitch], s->buf_len - 2*pitch);
if (len - in_len < pitch) if (len - in_len < pitch)
{ {
/* Cannot continue without more samples */ /* Cannot continue without more samples */
memcpy(&s->buf[s->buf_len - pitch], &in[in_len], sizeof(int16_t)*(len - in_len)); vec_copyi16(&s->buf[s->buf_len - pitch], &in[in_len], len - in_len);
s->fill += (len - in_len - pitch); s->fill += (len - in_len - pitch);
return out_len; return out_len;
} }
memcpy(&s->buf[s->buf_len - pitch], &in[in_len], sizeof(int16_t)*pitch); vec_copyi16(&s->buf[s->buf_len - pitch], &in[in_len], pitch);
in_len += pitch; in_len += pitch;
} }
else else
{ {
/* Slow down - insert a chunk of data */ /* Slow down - insert a chunk of data */
memcpy(&out[out_len], s->buf, sizeof(int16_t)*pitch); vec_copyi16(&out[out_len], s->buf, pitch);
out_len += pitch; out_len += pitch;
overlap_add(&s->buf[pitch], s->buf, pitch); overlap_add(&s->buf[pitch], s->buf, pitch);
} }

View File

@ -226,7 +226,7 @@ int main(int argc, char *argv[])
} }
printf("Test passed\n"); printf("Test passed\n");
t81_t82_arith_encode_free(se); t81_t82_arith_encode_free(se);
t81_t82_arith_encode_free(sd); t81_t82_arith_decode_free(sd);
printf("Tests passed\n"); printf("Tests passed\n");
return 0; return 0;
} }