From 164fa133dc39e79a8f97d5a4e985285da0d13bad Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Fri, 22 Aug 2014 01:33:22 +0000 Subject: [PATCH] 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. --- src/switch_stfu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; } -- 2.47.3