diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-10-08 08:26:02 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-10-08 12:56:09 +0200 |
commit | 223a67e572918e6176cf10dfea86331e89bc6226 (patch) | |
tree | b7f83794111d18d1be53cd1b5e27b7df3eea7c00 /src/nspawn | |
parent | sd-bus: introduce bus_process_cmsg() (diff) | |
download | systemd-223a67e572918e6176cf10dfea86331e89bc6226.tar.xz systemd-223a67e572918e6176cf10dfea86331e89bc6226.zip |
tree-wide: replace reallocarray() with GREEDY_REALLOC()
Diffstat (limited to 'src/nspawn')
-rw-r--r-- | src/nspawn/nspawn-bind-user.c | 6 | ||||
-rw-r--r-- | src/nspawn/nspawn-mount.c | 6 | ||||
-rw-r--r-- | src/nspawn/nspawn-oci.c | 35 |
3 files changed, 15 insertions, 32 deletions
diff --git a/src/nspawn/nspawn-bind-user.c b/src/nspawn/nspawn-bind-user.c index 0960a6dcea..d64a89f161 100644 --- a/src/nspawn/nspawn-bind-user.c +++ b/src/nspawn/nspawn-bind-user.c @@ -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), diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 874d54e734..3e579480fd 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -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)++; diff --git a/src/nspawn/nspawn-oci.c b/src/nspawn/nspawn-oci.c index 11ea744562..3228b19bba 100644 --- a/src/nspawn/nspawn-oci.c +++ b/src/nspawn/nspawn-oci.c @@ -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, |