提交 164fa133 authored 作者: Travis Cross's avatar Travis Cross

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.
上级 2cf6fd72
......@@ -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;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论