From: Travis Cross Date: Fri, 22 Aug 2014 01:33:22 +0000 (+0000) Subject: Refactor to avoid warning about realloc usage X-Git-Tag: v1.4.8~5^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=164fa133dc39e79a8f97d5a4e985285da0d13bad;p=thirdparty%2Ffreeswitch.git Refactor to avoid warning about realloc usage 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. --- diff --git a/src/switch_stfu.c b/src/switch_stfu.c index e92d138fde..5bb5f50afe 100644 --- a/src/switch_stfu.c +++ b/src/switch_stfu.c @@ -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; }