Skip to content

Commit

Permalink
lib: use XREALLOC over realloc avoid coverity warning
Browse files Browse the repository at this point in the history
I believe coverity is complaining that the current code does not handle the
realloc fail case, in which case the original pointer is not freed, but NULL is
returned. The code assert()s it's not failed but that is not strong enough it
needs to abort which XREALLOC does and is a better integration into FRR-inrfa
anyway.

Signed-off-by: Christian Hopps <[email protected]>
  • Loading branch information
choppsv1 committed Sep 28, 2023
1 parent 8640fc9 commit 2783614
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/darr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
#include <zebra.h>
#include "darr.h"
#include "memory.h"

DEFINE_MTYPE_STATIC(LIB, DARR, "Dynamic Array");

void __dar_resize(void **a, uint count, size_t esize);

Expand Down Expand Up @@ -56,15 +59,12 @@ void *__darr_resize(void *a, uint count, size_t esize)
uint ncount = darr_next_count(count, esize);
size_t osz = (a == NULL) ? 0 : darr_size(darr_cap(a), esize);
size_t sz = darr_size(ncount, esize);
struct darr_metadata *dm = realloc(a ? _darr_meta(a) : NULL, sz);
/* do *not* use a */
struct darr_metadata *dm = XREALLOC(MTYPE_DARR,
a ? _darr_meta(a) : NULL, sz);

assert(dm);
if (sz > osz)
memset((char *)dm + osz, 0, sz - osz);

dm->cap = ncount;

return (void *)(dm + 1);
}

Expand Down

0 comments on commit 2783614

Please sign in to comment.