From: Yu Watanabe Date: Wed, 20 Aug 2025 07:49:32 +0000 (+0900) Subject: boot: add assertions X-Git-Tag: v259-rc1~573 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb654a769da308ed1f3fd502b3148827d30c2028;p=thirdparty%2Fsystemd.git boot: add assertions To silence coverity. Closes CID#1620098. --- 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; }