tree-wide: replace reallocarray() with GREEDY_REALLOC()

This commit is contained in:
Yu Watanabe
2024-10-08 15:26:02 +09:00
parent 5f9f38b8df
commit 223a67e572
18 changed files with 81 additions and 177 deletions

View File

@@ -2377,7 +2377,6 @@ int bus_exec_context_set_transient_property(
for (;;) {
_cleanup_free_ void *copy = NULL;
struct iovec *t;
const char *eq;
const void *p;
size_t sz;
@@ -2404,13 +2403,6 @@ int bus_exec_context_set_transient_property(
if (!journal_field_valid(p, eq - (const char*) p, false))
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
if (!t)
return -ENOMEM;
c->log_extra_fields = t;
}
copy = memdup_suffix0(p, sz);
if (!copy)
return -ENOMEM;
@@ -2419,10 +2411,12 @@ int bus_exec_context_set_transient_property(
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
return -ENOMEM;
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
copy = NULL;
TAKE_PTR(copy);
}
n++;

View File

@@ -2935,7 +2935,6 @@ int config_parse_log_extra_fields(
for (const char *p = rvalue;;) {
_cleanup_free_ char *word = NULL, *k = NULL;
struct iovec *t;
const char *eq;
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
@@ -2965,14 +2964,11 @@ int config_parse_log_extra_fields(
continue;
}
t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
if (!t)
if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
return log_oom();
c->log_extra_fields = t;
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k);
k = NULL;
TAKE_PTR(k);
}
}

View File

@@ -2837,7 +2837,6 @@ MountImage* mount_image_free_many(MountImage *m, size_t *n) {
int mount_image_add(MountImage **m, size_t *n, const MountImage *item) {
_cleanup_free_ char *s = NULL, *d = NULL;
_cleanup_(mount_options_free_allp) MountOptions *options = NULL;
MountImage *c;
assert(m);
assert(n);
@@ -2870,13 +2869,10 @@ int mount_image_add(MountImage **m, size_t *n, const MountImage *item) {
LIST_APPEND(mount_options, options, TAKE_PTR(o));
}
c = reallocarray(*m, *n + 1, sizeof(MountImage));
if (!c)
if (!GREEDY_REALLOC(*m, *n + 1))
return -ENOMEM;
*m = c;
c[(*n)++] = (MountImage) {
(*m)[(*n)++] = (MountImage) {
.source = TAKE_PTR(s),
.destination = TAKE_PTR(d),
.mount_options = TAKE_PTR(options),
@@ -2905,7 +2901,6 @@ int temporary_filesystem_add(
const char *options) {
_cleanup_free_ char *p = NULL, *o = NULL;
TemporaryFileSystem *c;
assert(t);
assert(n);
@@ -2921,13 +2916,10 @@ int temporary_filesystem_add(
return -ENOMEM;
}
c = reallocarray(*t, *n + 1, sizeof(TemporaryFileSystem));
if (!c)
if (!GREEDY_REALLOC(*t, *n + 1))
return -ENOMEM;
*t = c;
c[(*n)++] = (TemporaryFileSystem) {
(*t)[(*n)++] = (TemporaryFileSystem) {
.path = TAKE_PTR(p),
.options = TAKE_PTR(o),
};

View File

@@ -606,19 +606,15 @@ static int parse_argv(int argc, char *argv[]) {
else if (streq(slot, "tpm2"))
arg_wipe_slots_mask |= 1U << ENROLL_TPM2;
else {
int *a;
r = safe_atou(slot, &n);
if (r < 0)
return log_error_errno(r, "Failed to parse slot index: %s", slot);
if (n > INT_MAX)
return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Slot index out of range: %u", n);
a = reallocarray(arg_wipe_slots, arg_n_wipe_slots + 1, sizeof(int));
if (!a)
if (!GREEDY_REALLOC(arg_wipe_slots, arg_n_wipe_slots + 1))
return log_oom();
arg_wipe_slots = a;
arg_wipe_slots[arg_n_wipe_slots++] = (int) n;
}
}

View File

@@ -51,7 +51,7 @@ int deserialize_in_addrs(struct in_addr **ret, const char *string) {
for (;;) {
_cleanup_free_ char *word = NULL;
struct in_addr *new_addresses;
union in_addr_union a;
int r;
r = extract_first_word(&string, &word, NULL, 0);
@@ -60,17 +60,13 @@ int deserialize_in_addrs(struct in_addr **ret, const char *string) {
if (r == 0)
break;
new_addresses = reallocarray(addresses, size + 1, sizeof(struct in_addr));
if (!new_addresses)
return -ENOMEM;
else
addresses = new_addresses;
r = inet_pton(AF_INET, word, &(addresses[size]));
if (r <= 0)
if (in_addr_from_string(AF_INET, word, &a) < 0)
continue;
size++;
if (!GREEDY_REALLOC(addresses, size + 1))
return -ENOMEM;
addresses[size++] = a.in;
}
*ret = size > 0 ? TAKE_PTR(addresses) : NULL;
@@ -104,7 +100,7 @@ int deserialize_in6_addrs(struct in6_addr **ret, const char *string) {
for (;;) {
_cleanup_free_ char *word = NULL;
struct in6_addr *new_addresses;
union in_addr_union a;
int r;
r = extract_first_word(&string, &word, NULL, 0);
@@ -113,17 +109,13 @@ int deserialize_in6_addrs(struct in6_addr **ret, const char *string) {
if (r == 0)
break;
new_addresses = reallocarray(addresses, size + 1, sizeof(struct in6_addr));
if (!new_addresses)
return -ENOMEM;
else
addresses = new_addresses;
r = inet_pton(AF_INET6, word, &(addresses[size]));
if (r <= 0)
if (in_addr_from_string(AF_INET6, word, &a) < 0)
continue;
size++;
if (!GREEDY_REALLOC(addresses, size + 1))
return -ENOMEM;
addresses[size++] = a.in6;
}
*ret = TAKE_PTR(addresses);

View File

@@ -602,7 +602,6 @@ static bool map_ok(const sd_bus_error_map *map) {
}
_public_ int sd_bus_error_add_map(const sd_bus_error_map *map) {
const sd_bus_error_map **maps = NULL;
unsigned n = 0;
assert_return(map, -EINVAL);
@@ -613,13 +612,11 @@ _public_ int sd_bus_error_add_map(const sd_bus_error_map *map) {
if (additional_error_maps[n] == map)
return 0;
maps = reallocarray(additional_error_maps, n + 2, sizeof(struct sd_bus_error_map*));
if (!maps)
if (!GREEDY_REALLOC(additional_error_maps, n + 2))
return -ENOMEM;
maps[n] = map;
maps[n+1] = NULL;
additional_error_maps[n] = map;
additional_error_maps[n+1] = NULL;
additional_error_maps = maps;
return 1;
}

View File

@@ -1276,7 +1276,7 @@ static void *message_extend_body(
}
static int message_push_fd(sd_bus_message *m, int fd) {
int *f, copy;
int copy;
assert(m);
@@ -1290,15 +1290,13 @@ static int message_push_fd(sd_bus_message *m, int fd) {
if (copy < 0)
return -errno;
f = reallocarray(m->fds, m->n_fds + 1, sizeof(int));
if (!f) {
if (!GREEDY_REALLOC(m->fds, m->n_fds + 1)) {
m->poisoned = true;
safe_close(copy);
return -ENOMEM;
}
m->fds = f;
m->fds[m->n_fds] = copy;
m->fds[m->n_fds] = copy; /* m->n_fds will be incremented by the caller later */
m->free_fds = true;
return copy;

View File

@@ -1048,9 +1048,8 @@ _public_ int sd_get_sessions(char ***sessions) {
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d = NULL;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
size_t n = 0;
d = opendir("/run/systemd/users/");
if (!d) {
@@ -1063,38 +1062,31 @@ _public_ int sd_get_uids(uid_t **users) {
}
FOREACH_DIRENT_ALL(de, d, return -errno) {
int k;
uid_t uid;
if (!dirent_is_file(de))
continue;
k = parse_uid(de->d_name, &uid);
if (k < 0)
if (parse_uid(de->d_name, &uid) < 0)
continue;
if (users) {
if ((unsigned) r >= n) {
uid_t *t;
if (!GREEDY_REALLOC(l, n + 1))
return -ENOMEM;
n = MAX(16, 2*r);
t = reallocarray(l, n, sizeof(uid_t));
if (!t)
return -ENOMEM;
l[n] = uid;
}
l = t;
}
assert((unsigned) r < n);
l[r++] = uid;
} else
r++;
n++;
}
if (n > INT_MAX)
return -EOVERFLOW;
if (users)
*users = TAKE_PTR(l);
return r;
return (int) n;
}
_public_ int sd_get_machine_names(char ***machines) {

View File

@@ -201,7 +201,6 @@ int config_parse_dns(
for (const char *p = rvalue;;) {
_cleanup_(in_addr_full_freep) struct in_addr_full *dns = NULL;
_cleanup_free_ char *w = NULL;
struct in_addr_full **m;
r = extract_first_word(&p, &w, NULL, 0);
if (r == -ENOMEM)
@@ -224,12 +223,10 @@ int config_parse_dns(
if (IN_SET(dns->port, 53, 853))
dns->port = 0;
m = reallocarray(n->dns, n->n_dns + 1, sizeof(struct in_addr_full*));
if (!m)
if (!GREEDY_REALLOC(n->dns, n->n_dns + 1))
return log_oom();
m[n->n_dns++] = TAKE_PTR(dns);
n->dns = m;
n->dns[n->n_dns++] = TAKE_PTR(dns);
}
}

View File

@@ -1331,13 +1331,10 @@ int config_parse_radv_dns(
}
}
struct in6_addr *m;
m = reallocarray(n->router_dns, n->n_router_dns + 1, sizeof(struct in6_addr));
if (!m)
if (!GREEDY_REALLOC(n->router_dns, n->n_router_dns + 1))
return log_oom();
m[n->n_router_dns++] = a.in6;
n->router_dns = m;
n->router_dns[n->n_router_dns++] = a.in6;
}
}

View File

@@ -230,7 +230,6 @@ int bind_user_prepare(
_cleanup_(user_record_unrefp) UserRecord *u = NULL, *cu = NULL;
_cleanup_(group_record_unrefp) GroupRecord *g = NULL, *cg = NULL;
_cleanup_free_ char *sm = NULL, *sd = NULL;
CustomMount *cm;
r = userdb_by_name(*n, USERDB_DONT_SYNTHESIZE, &u);
if (r < 0)
@@ -290,12 +289,9 @@ int bind_user_prepare(
if (!sd)
return log_oom();
cm = reallocarray(*custom_mounts, *n_custom_mounts + 1, sizeof(CustomMount));
if (!cm)
if (!GREEDY_REALLOC(*custom_mounts, *n_custom_mounts + 1))
return log_oom();
*custom_mounts = cm;
(*custom_mounts)[(*n_custom_mounts)++] = (CustomMount) {
.type = CUSTOM_MOUNT_BIND,
.source = TAKE_PTR(sm),

View File

@@ -27,18 +27,16 @@
#include "user-util.h"
CustomMount* custom_mount_add(CustomMount **l, size_t *n, CustomMountType t) {
CustomMount *c, *ret;
CustomMount *ret;
assert(l);
assert(n);
assert(t >= 0);
assert(t < _CUSTOM_MOUNT_TYPE_MAX);
c = reallocarray(*l, *n + 1, sizeof(CustomMount));
if (!c)
if (!GREEDY_REALLOC(*l, *n + 1))
return NULL;
*l = c;
ret = *l + *n;
(*n)++;

View File

@@ -341,7 +341,7 @@ static int oci_supplementary_gids(const char *name, sd_json_variant *v, sd_json_
int r;
JSON_VARIANT_ARRAY_FOREACH(e, v) {
gid_t gid, *a;
gid_t gid;
if (!sd_json_variant_is_unsigned(e))
return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL),
@@ -351,11 +351,9 @@ static int oci_supplementary_gids(const char *name, sd_json_variant *v, sd_json_
if (r < 0)
return r;
a = reallocarray(s->supplementary_gids, s->n_supplementary_gids + 1, sizeof(gid_t));
if (!a)
if (!GREEDY_REALLOC(s->supplementary_gids, s->n_supplementary_gids + 1))
return log_oom();
s->supplementary_gids = a;
s->supplementary_gids[s->n_supplementary_gids++] = gid;
}
@@ -805,15 +803,12 @@ static int oci_devices(const char *name, sd_json_variant *v, sd_json_dispatch_fl
{}
};
DeviceNode *node, *nodes;
DeviceNode *node;
nodes = reallocarray(s->extra_nodes, s->n_extra_nodes + 1, sizeof(DeviceNode));
if (!nodes)
if (!GREEDY_REALLOC(s->extra_nodes, s->n_extra_nodes + 1))
return log_oom();
s->extra_nodes = nodes;
node = nodes + s->n_extra_nodes;
node = s->extra_nodes + s->n_extra_nodes;
*node = (DeviceNode) {
.uid = UID_INVALID,
.gid = GID_INVALID,
@@ -960,7 +955,7 @@ static int oci_cgroup_devices(const char *name, sd_json_variant *v, sd_json_disp
struct device_data data = {
.major = UINT_MAX,
.minor = UINT_MAX,
}, *a;
};
static const sd_json_dispatch_field table[] = {
{ "allow", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(struct device_data, allow), SD_JSON_MANDATORY },
@@ -1012,11 +1007,9 @@ static int oci_cgroup_devices(const char *name, sd_json_variant *v, sd_json_disp
"Device cgroup allow list entries with no type not supported.");
}
a = reallocarray(list, n_list + 1, sizeof(struct device_data));
if (!a)
if (!GREEDY_REALLOC(list, n_list + 1))
return log_oom();
list = a;
list[n_list++] = data;
}
@@ -1750,14 +1743,12 @@ static int oci_seccomp_args(const char *name, sd_json_variant *v, sd_json_dispat
{},
};
struct scmp_arg_cmp *a, *p;
struct scmp_arg_cmp *p;
int expected;
a = reallocarray(rule->arguments, rule->n_arguments + 1, sizeof(struct syscall_rule));
if (!a)
if (!GREEDY_REALLOC(rule->arguments, rule->n_arguments + 1))
return log_oom();
rule->arguments = a;
p = rule->arguments + rule->n_arguments;
*p = (struct scmp_arg_cmp) {
@@ -2014,7 +2005,7 @@ static int oci_hooks_array(const char *name, sd_json_variant *v, sd_json_dispatc
{}
};
OciHook *a, **array, *new_item;
OciHook **array, *new_item;
size_t *n_array;
if (streq(name, "prestart")) {
@@ -2029,12 +2020,10 @@ static int oci_hooks_array(const char *name, sd_json_variant *v, sd_json_dispatc
n_array = &s->n_oci_hooks_poststop;
}
a = reallocarray(*array, *n_array + 1, sizeof(OciHook));
if (!a)
if (!GREEDY_REALLOC(*array, *n_array + 1))
return log_oom();
*array = a;
new_item = a + *n_array;
new_item = *array + *n_array;
*new_item = (OciHook) {
.timeout = USEC_INFINITY,

View File

@@ -904,7 +904,6 @@ static int portable_changes_add(
const char *source) {
_cleanup_free_ char *p = NULL, *s = NULL;
PortableChange *c;
int r;
assert(path);
@@ -918,10 +917,8 @@ static int portable_changes_add(
if (!changes)
return 0;
c = reallocarray(*changes, *n_changes + 1, sizeof(PortableChange));
if (!c)
if (!GREEDY_REALLOC(*changes, *n_changes + 1))
return -ENOMEM;
*changes = c;
r = path_simplify_alloc(path, &p);
if (r < 0)
@@ -931,7 +928,7 @@ static int portable_changes_add(
if (r < 0)
return r;
c[(*n_changes)++] = (PortableChange) {
(*changes)[(*n_changes)++] = (PortableChange) {
.type_or_errno = type_or_errno,
.path = TAKE_PTR(p),
.source = TAKE_PTR(s),

View File

@@ -2423,15 +2423,13 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
if (r >= 0) {
assert(r >= 0 && r < 256);
status = reallocarray(status, n_status + 1, sizeof(int));
if (!status)
if (!GREEDY_REALLOC(status, n_status + 1))
return log_oom();
status[n_status++] = r;
} else if ((r = signal_from_string(word)) >= 0) {
signal = reallocarray(signal, n_signal + 1, sizeof(int));
if (!signal)
if (!GREEDY_REALLOC(signal, n_signal + 1))
return log_oom();
signal[n_signal++] = r;

View File

@@ -76,18 +76,15 @@ static int trie_children_cmp(const struct trie_child_entry *a, const struct trie
}
static int node_add_child(struct trie *trie, struct trie_node *node, struct trie_node *node_child, uint8_t c) {
struct trie_child_entry *child;
/* extend array, add new entry, sort for bisection */
child = reallocarray(node->children, node->children_count + 1, sizeof(struct trie_child_entry));
if (!child)
if (!GREEDY_REALLOC(node->children, node->children_count + 1))
return -ENOMEM;
node->children = child;
trie->children_count++;
node->children[node->children_count].c = c;
node->children[node->children_count].child = node_child;
node->children_count++;
node->children[node->children_count++] = (struct trie_child_entry) {
.c = c,
.child = node_child,
};
typesafe_qsort(node->children, node->children_count, trie_children_cmp);
trie->nodes_count++;
@@ -136,7 +133,6 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
const char *key, const char *value,
const char *filename, uint16_t file_priority, uint32_t line_number, bool compat) {
ssize_t k, v, fn = 0;
struct trie_value_entry *val;
k = strbuf_add_string(trie->strings, key);
if (k < 0)
@@ -155,7 +151,7 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
struct trie_value_entry search = {
.key_off = k,
.value_off = v,
};
}, *val;
val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie);
if (val) {
@@ -170,19 +166,17 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
}
/* extend array, add new entry, sort for bisection */
val = reallocarray(node->values, node->values_count + 1, sizeof(struct trie_value_entry));
if (!val)
if (!GREEDY_REALLOC(node->values, node->values_count + 1))
return -ENOMEM;
trie->values_count++;
node->values = val;
node->values[node->values_count] = (struct trie_value_entry) {
node->values[node->values_count++] = (struct trie_value_entry) {
.key_off = k,
.value_off = v,
.filename_off = fn,
.file_priority = file_priority,
.line_number = line_number,
};
node->values_count++;
typesafe_qsort_r(node->values, node->values_count, trie_values_cmp, trie);
return 0;
}

View File

@@ -295,7 +295,6 @@ InstallChangeType install_changes_add(
const char *source) {
_cleanup_free_ char *p = NULL, *s = NULL;
InstallChange *c;
int r;
assert(!changes == !n_changes);
@@ -310,10 +309,8 @@ InstallChangeType install_changes_add(
if (!changes)
return type;
c = reallocarray(*changes, *n_changes + 1, sizeof(InstallChange));
if (!c)
if (!GREEDY_REALLOC(*changes, *n_changes + 1))
return -ENOMEM;
*changes = c;
r = path_simplify_alloc(path, &p);
if (r < 0)
@@ -323,7 +320,7 @@ InstallChangeType install_changes_add(
if (r < 0)
return r;
c[(*n_changes)++] = (InstallChange) {
(*changes)[(*n_changes)++] = (InstallChange) {
.type = type,
.path = TAKE_PTR(p),
.source = TAKE_PTR(s),

View File

@@ -771,8 +771,6 @@ static int dispatch_pkcs11_key(const char *name, sd_json_variant *variant, sd_js
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of objects.", strna(name));
JSON_VARIANT_ARRAY_FOREACH(e, variant) {
Pkcs11EncryptedKey *array, *k;
static const sd_json_dispatch_field pkcs11_key_dispatch_table[] = {
{ "uri", SD_JSON_VARIANT_STRING, dispatch_pkcs11_uri, offsetof(Pkcs11EncryptedKey, uri), SD_JSON_MANDATORY },
{ "data", SD_JSON_VARIANT_STRING, dispatch_pkcs11_key_data, 0, SD_JSON_MANDATORY },
@@ -783,12 +781,10 @@ static int dispatch_pkcs11_key(const char *name, sd_json_variant *variant, sd_js
if (!sd_json_variant_is_object(e))
return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not an object.");
array = reallocarray(h->pkcs11_encrypted_key, h->n_pkcs11_encrypted_key + 1, sizeof(Pkcs11EncryptedKey));
if (!array)
if (!GREEDY_REALLOC(h->pkcs11_encrypted_key, h->n_pkcs11_encrypted_key + 1))
return log_oom();
h->pkcs11_encrypted_key = array;
k = h->pkcs11_encrypted_key + h->n_pkcs11_encrypted_key;
Pkcs11EncryptedKey *k = h->pkcs11_encrypted_key + h->n_pkcs11_encrypted_key;
*k = (Pkcs11EncryptedKey) {};
r = sd_json_dispatch(e, pkcs11_key_dispatch_table, flags, k);
@@ -834,20 +830,16 @@ static int dispatch_fido2_hmac_credential_array(const char *name, sd_json_varian
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of strings.", strna(name));
JSON_VARIANT_ARRAY_FOREACH(e, variant) {
Fido2HmacCredential *array;
size_t l;
void *b;
array = reallocarray(h->fido2_hmac_credential, h->n_fido2_hmac_credential + 1, sizeof(Fido2HmacCredential));
if (!array)
if (!GREEDY_REALLOC(h->fido2_hmac_credential, h->n_fido2_hmac_credential + 1))
return log_oom();
r = sd_json_variant_unbase64(e, &b, &l);
if (r < 0)
return json_log(variant, flags, r, "Failed to decode FIDO2 credential ID: %m");
h->fido2_hmac_credential = array;
h->fido2_hmac_credential[h->n_fido2_hmac_credential++] = (Fido2HmacCredential) {
.id = b,
.size = l,
@@ -889,8 +881,6 @@ static int dispatch_fido2_hmac_salt(const char *name, sd_json_variant *variant,
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of objects.", strna(name));
JSON_VARIANT_ARRAY_FOREACH(e, variant) {
Fido2HmacSalt *array, *k;
static const sd_json_dispatch_field fido2_hmac_salt_dispatch_table[] = {
{ "credential", SD_JSON_VARIANT_STRING, dispatch_fido2_hmac_credential, offsetof(Fido2HmacSalt, credential), SD_JSON_MANDATORY },
{ "salt", SD_JSON_VARIANT_STRING, dispatch_fido2_hmac_salt_value, 0, SD_JSON_MANDATORY },
@@ -904,12 +894,10 @@ static int dispatch_fido2_hmac_salt(const char *name, sd_json_variant *variant,
if (!sd_json_variant_is_object(e))
return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not an object.");
array = reallocarray(h->fido2_hmac_salt, h->n_fido2_hmac_salt + 1, sizeof(Fido2HmacSalt));
if (!array)
if (!GREEDY_REALLOC(h->fido2_hmac_salt, h->n_fido2_hmac_salt + 1))
return log_oom();
h->fido2_hmac_salt = array;
k = h->fido2_hmac_salt + h->n_fido2_hmac_salt;
Fido2HmacSalt *k = h->fido2_hmac_salt + h->n_fido2_hmac_salt;
*k = (Fido2HmacSalt) {
.uv = -1,
.up = -1,
@@ -937,8 +925,6 @@ static int dispatch_recovery_key(const char *name, sd_json_variant *variant, sd_
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of objects.", strna(name));
JSON_VARIANT_ARRAY_FOREACH(e, variant) {
RecoveryKey *array, *k;
static const sd_json_dispatch_field recovery_key_dispatch_table[] = {
{ "type", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, 0, SD_JSON_MANDATORY },
{ "hashedPassword", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(RecoveryKey, hashed_password), SD_JSON_MANDATORY },
@@ -948,12 +934,10 @@ static int dispatch_recovery_key(const char *name, sd_json_variant *variant, sd_
if (!sd_json_variant_is_object(e))
return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not an object.");
array = reallocarray(h->recovery_key, h->n_recovery_key + 1, sizeof(RecoveryKey));
if (!array)
if (!GREEDY_REALLOC(h->recovery_key, h->n_recovery_key + 1))
return log_oom();
h->recovery_key = array;
k = h->recovery_key + h->n_recovery_key;
RecoveryKey *k = h->recovery_key + h->n_recovery_key;
*k = (RecoveryKey) {};
r = sd_json_dispatch(e, recovery_key_dispatch_table, flags, k);