]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Refactor to avoid warning about realloc usage
authorTravis Cross <tc@traviscross.com>
Fri, 22 Aug 2014 01:33:22 +0000 (01:33 +0000)
committerTravis Cross <tc@traviscross.com>
Fri, 22 Aug 2014 01:36:59 +0000 (01:36 +0000)
Clang's static analyzer noticed the result of realloc was being
assigned to a pointer of a different type than was used to calculate
the new size.  We can make things simpler and more idiomatic here by
using the correct pointer type and letting C's pointer arithmetic
automatically handle some multiplication.

We also use the distributive property here to simplify the calculation
for memset.

src/switch_stfu.c

index e92d138fde87836d323e18d7d1663294e3b4c172..5bb5f50afef1e06d0b6d8223d248a7ba545f6413 100644 (file)
@@ -167,7 +167,7 @@ void stfu_global_set_default_logger(int level)
 
 static stfu_status_t stfu_n_resize_aqueue(stfu_queue_t *queue, uint32_t qlen)
 {
-    unsigned char *m;
+    struct stfu_frame *m;
 
     if (qlen <= queue->real_array_size) {
         queue->array_size = qlen;
@@ -177,8 +177,8 @@ static stfu_status_t stfu_n_resize_aqueue(stfu_queue_t *queue, uint32_t qlen)
     } else {
         m = realloc(queue->array, qlen * sizeof(struct stfu_frame));
         assert(m);
-        memset(m + queue->array_size * sizeof(struct stfu_frame), 0, (qlen * sizeof(struct stfu_frame)) - (queue->array_size * sizeof(struct stfu_frame)));
-        queue->array = (struct stfu_frame *) m;
+        memset(m + queue->array_size, 0, (qlen - queue->array_size) * sizeof(struct stfu_frame));
+        queue->array = m;
         queue->real_array_size = queue->array_size = qlen;
     }