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.
This commit is contained in:
parent
2cf6fd728c
commit
164fa133dc
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue