From eb654a769da308ed1f3fd502b3148827d30c2028 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 20 Aug 2025 16:49:32 +0900 Subject: [PATCH] boot: add assertions To silence coverity. Closes CID#1620098. --- src/boot/util.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/boot/util.h b/src/boot/util.h index 98e9ae576ee..e7a3ba03033 100644 --- a/src/boot/util.h +++ b/src/boot/util.h @@ -46,10 +46,16 @@ static inline void *xmalloc_multiply(size_t n, size_t size) { /* Use malloc attribute as this never returns p like userspace realloc. */ _malloc_ _alloc_(3) _returns_nonnull_ _warn_unused_result_ static inline void *xrealloc(void *p, size_t old_size, size_t new_size) { + assert(p || old_size == 0); + void *t = xmalloc(new_size); - new_size = MIN(old_size, new_size); - if (new_size > 0) - memcpy(t, p, new_size); + + size_t size = MIN(old_size, new_size); + if (size > 0) { + assert(p); + memcpy(t, p, size); + } + free(p); return t; } -- 2.47.3