Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:vlefebvre:unified
systemd
2005-libefi-util-introduce-xrealloc_extra_-k-_i...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2005-libefi-util-introduce-xrealloc_extra_-k-_item-s.patch of Package systemd
From 89a2ab66407327611c934273e24dab874ba0b3a6 Mon Sep 17 00:00:00 2001 From: Raito Bezarius <masterancpp@gmail.com> Date: Mon, 19 Jun 2023 14:41:38 +0200 Subject: [PATCH 5/7] libefi(util): introduce `xrealloc_extra_(k)_item(s)` This is helpful to extend of K items an existing NULL-terminated array, by default, we use it with an extension of K=1, in `boot.c` for loading a list of initrds and addons. --- src/boot/efi/boot.c | 14 ++++++++------ src/boot/efi/util.h | 9 +++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 15b365cf40..1795b7d6eb 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -1480,17 +1480,19 @@ static void boot_entry_add_type1( entry->devicetree = xstr8_to_path(value); } else if (streq8(key, "initrd")) { - entry->initrd = xrealloc( + entry->initrd = xrealloc_extra_item( + uint16_t, entry->initrd, - n_initrd == 0 ? 0 : (n_initrd + 1) * sizeof(uint16_t *), - (n_initrd + 2) * sizeof(uint16_t *)); + n_initrd + ); entry->initrd[n_initrd++] = xstr8_to_path(value); entry->initrd[n_initrd] = NULL; } else if (streq8(key, "add-on")) { - entry->addons = xrealloc( + entry->addons = xrealloc_extra_item( + uint16_t, entry->addons, - n_addons == 0 ? 0 : (n_addons + 1) * sizeof(uint16_t *), - (n_addons + 2) * sizeof(uint16_t *)); + n_addons + ); entry->addons[n_addons++] = xstr8_to_path(value); entry->addons[n_addons] = NULL; continue; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index aef831d132..f1c4d4a58e 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -57,6 +57,15 @@ static inline void* xmemdup(const void *p, size_t l) { return memcpy(xmalloc(l), p, l); } +static inline void **xrealloc_extra_k_items(void *p, size_t item_size, size_t current_size, size_t extra_elements) { + size_t new_size = (current_size + extra_elements + 1) * item_size; + if (current_size == 0) + return (void**)xrealloc(p, 0, new_size); + else + return (void**)xrealloc(p, (current_size + 1) * item_size, new_size); +} + +#define xrealloc_extra_item(type, p, current_size) ((type **) xrealloc_extra_k_items(p, current_size, sizeof(type), 1)) #define xnew(type, n) ((type *) xmalloc_multiply((n), sizeof(type))) typedef struct { -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor