]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
More fixes for Coverity issues
authorSteve Underwood <steveu@coppice.org>
Tue, 22 Jul 2014 02:51:42 +0000 (10:51 +0800)
committerSteve Underwood <steveu@coppice.org>
Tue, 22 Jul 2014 02:51:42 +0000 (10:51 +0800)
libs/spandsp/src/spandsp/private/super_tone_tx.h
libs/spandsp/src/spandsp/super_tone_tx.h
libs/spandsp/src/spandsp/vector_int.h
libs/spandsp/src/super_tone_tx.c
libs/spandsp/src/time_scale.c
libs/spandsp/tests/t81_t82_arith_coding_tests.c

index b6efced96548ec8afef852ba67d276bf7c211c59..cec758026dd9974528ef81e0bcfc5172b082e5fb 100644 (file)
@@ -28,7 +28,7 @@
 
 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 length;
     int cycles;
@@ -38,12 +38,12 @@ struct super_tone_tx_step_s
 
 struct super_tone_tx_state_s
 {
-    tone_gen_tone_descriptor_t tone[4];
-    uint32_t phase[4];
+    tone_gen_tone_descriptor_t tone[SUPER_TONE_TX_MAX_TONES];
+    uint32_t phase[SUPER_TONE_TX_MAX_TONES];
     int current_position;
     int level;
-    super_tone_tx_step_t *levels[4];
-    int cycles[4];
+    super_tone_tx_step_t *levels[SUPER_TONE_TX_MAX_LEVELS];
+    int cycles[SUPER_TONE_TX_MAX_LEVELS];
 };
 
 #endif
index 55b8d670f0fc3cd6261d8a4e4fb05077a327e9eb..879319ae47cfa86a952f7d05532c0cc36be92eba 100644 (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_state_s super_tone_tx_state_t;
index daec30670e93c63ddb335801ea47ddb596c73eb1..775d525c863a061a75384c0b3ef546121523ab89 100644 (file)
@@ -49,6 +49,24 @@ static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n)
 }
 /*- 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)
 {
     memset(z, 0, n*sizeof(z[0]));
index 5b8ab4303d999115123db79f91323937d4e6479a..cd6ac8290e3f677918f62cf96d21d0a629c70709 100644 (file)
@@ -170,7 +170,7 @@ SPAN_DECLARE(int) super_tone_tx(super_tone_tx_state_t *s, int16_t amp[], int max
     float xamp;
     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;
     samples = 0;
     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)
             {
                 /* 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];
             }
             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++)
                 {
                     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)
                             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... */
         if (tree->nest)
         {
-            tree = tree->nest;
-            s->levels[++s->level] = tree;
-            s->cycles[s->level] = tree->cycles;
+            if (s->level < SUPER_TONE_TX_MAX_LEVELS - 1)
+            {
+                /* 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
         {
index c8b6b238258eea468db8f70dedd25c093695acc9..5337e4ad0cd65396209e17cf609a37d5c3712f09 100644 (file)
@@ -52,8 +52,9 @@
 #include "spandsp/telephony.h"
 #include "spandsp/alloc.h"
 #include "spandsp/fast_convert.h"
-#include "spandsp/time_scale.h"
+#include "spandsp/vector_int.h"
 #include "spandsp/saturated.h"
+#include "spandsp/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)
     {
         /* 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;
         return out_len;
     }
     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;
     s->fill = s->buf_len;
     while (s->fill == 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;
             if (len - in_len < s->buf_len)
             {
                 /* 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->lcp -= s->buf_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;
             s->lcp -= s->buf_len;
         }
         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;
-            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)
             {
                 /* 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->lcp = 0;
                 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;
             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 */
                 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)
                 {
                     /* 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);
                     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;
             }
             else
             {
                 /* 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;
                 overlap_add(&s->buf[pitch], s->buf, pitch);
             }
index 84a61a5df1d6c94b84cd1cb56f1fee1ed07f70bf..7df59567ea4df43a38cc2a5801a6d469e91cb0f7 100644 (file)
@@ -226,7 +226,7 @@ int main(int argc, char *argv[])
     }
     printf("Test passed\n");
     t81_t82_arith_encode_free(se);
-    t81_t82_arith_encode_free(sd);
+    t81_t82_arith_decode_free(sd);
     printf("Tests passed\n");
     return 0;
 }