From: anonymix007 <48598263+anonymix007@users.noreply.github.com> Date: Sat, 31 Aug 2024 18:34:56 +0000 (+0300) Subject: boot: Add xcalloc and xcalloc_multiply X-Git-Tag: v257-rc1~254^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1fcdf22573a7348a121f51e826ce9c6547b11116;p=thirdparty%2Fsystemd.git boot: Add xcalloc and xcalloc_multiply --- diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index e5f88ec5f0a..35f6c80a022 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -2,8 +2,10 @@ #pragma once #include "efi.h" +#include "efi-string.h" #include "log.h" #include "proto/file-io.h" +#include "memory-util-fundamental.h" #include "string-util-fundamental.h" /* This is provided by the linker. */ @@ -31,6 +33,19 @@ static inline void freep(void *p) { _malloc_ _alloc_(1) _returns_nonnull_ _warn_unused_result_ void *xmalloc(size_t size); +_malloc_ _alloc_(1) _returns_nonnull_ _warn_unused_result_ +static inline void *xcalloc(size_t size) { + void *t = xmalloc(size); + memzero(t, size); + return t; +} + +_malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_ +static inline void *xcalloc_multiply(size_t n, size_t size) { + assert_se(MUL_ASSIGN_SAFE(&size, n)); + return xcalloc(size); +} + _malloc_ _alloc_(1, 2) _returns_nonnull_ _warn_unused_result_ static inline void *xmalloc_multiply(size_t n, size_t size) { assert_se(MUL_ASSIGN_SAFE(&size, n));