From 1fcdf22573a7348a121f51e826ce9c6547b11116 Mon Sep 17 00:00:00 2001 From: anonymix007 <48598263+anonymix007@users.noreply.github.com> Date: Sat, 31 Aug 2024 21:34:56 +0300 Subject: [PATCH] boot: Add xcalloc and xcalloc_multiply --- src/boot/efi/util.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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)); -- 2.47.3