diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 5999bc0590..f13282c482 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -331,9 +331,8 @@ device_ip6_prefix_delegated(NMDevice *device, if (i == priv->ip6_prefix_delegations->len) { /* Allocate a delegation for new prefix. */ - g_array_set_size(priv->ip6_prefix_delegations, i + 1); - delegation = &g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); - delegation->subnets = g_hash_table_new(nm_direct_hash, NULL); + delegation = nm_g_array_append_new(priv->ip6_prefix_delegations, IP6PrefixDelegation); + delegation->subnets = g_hash_table_new(nm_direct_hash, NULL); delegation->next_subnet = 0; } diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c index c0680fb10f..70c8664666 100644 --- a/src/core/platform/nm-fake-platform.c +++ b/src/core/platform/nm-fake-platform.c @@ -234,8 +234,7 @@ link_add_pre(NMPlatform *platform, g_assert(!name || strlen(name) < IFNAMSIZ); - g_array_set_size(priv->links, priv->links->len + 1); - device = &g_array_index(priv->links, NMFakePlatformLink, priv->links->len - 1); + device = nm_g_array_append_new(priv->links, NMFakePlatformLink); ifindex = priv->links->len; memset(device, 0, sizeof(*device)); diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 35070baed1..8e975b64bd 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -360,8 +360,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class, name)) continue; - g_array_set_size(properties_override, properties_override->len + 1); - p = &g_array_index(properties_override, NMSettInfoProperty, properties_override->len - 1); + p = nm_g_array_append_new(properties_override, NMSettInfoProperty); memset(p, 0, sizeof(*p)); p->name = name; p->param_spec = property_specs[i]; diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index b6e57de144..9a7167f67f 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4247,13 +4247,13 @@ _nm_utils_generate_mac_address_mask_parse(const char *value, ouis = g_array_sized_new(FALSE, FALSE, sizeof(struct ether_addr), 4); do { + struct ether_addr *new; + s = s_next; s_next = _split_word(s); - g_array_set_size(ouis, ouis->len + 1); - if (!nm_utils_hwaddr_aton(s, - &g_array_index(ouis, struct ether_addr, ouis->len - 1), - ETH_ALEN)) { + new = nm_g_array_append_new(ouis, struct ether_addr); + if (!nm_utils_hwaddr_aton(s, new, ETH_ALEN)) { g_set_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 3cbb6a685d..03725b2558 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -2541,16 +2541,15 @@ _wireguard_update_from_peers_nla(CList *peers, GArray **p_allowed_ips, struct nl GArray *allowed_ips = *p_allowed_ips; nla_for_each_nested (attr, tb[WGPEER_A_ALLOWEDIPS], rem) { + NMPWireGuardAllowedIP *new; + if (!allowed_ips) { allowed_ips = g_array_new(FALSE, FALSE, sizeof(NMPWireGuardAllowedIP)); *p_allowed_ips = allowed_ips; - g_array_set_size(allowed_ips, 1); - } else - g_array_set_size(allowed_ips, allowed_ips->len + 1); + } - if (!_wireguard_update_from_allowed_ips_nla( - &g_array_index(allowed_ips, NMPWireGuardAllowedIP, allowed_ips->len - 1), - attr)) { + new = nm_g_array_append_new(allowed_ips, NMPWireGuardAllowedIP); + if (!_wireguard_update_from_allowed_ips_nla(new, attr)) { /* we ignore the error of parsing one allowed-ip. */ g_array_set_size(allowed_ips, allowed_ips->len - 1); continue; diff --git a/src/libnm-platform/nmp-netns.c b/src/libnm-platform/nmp-netns.c index 2563e8f640..b3e2e043c0 100644 --- a/src/libnm-platform/nmp-netns.c +++ b/src/libnm-platform/nmp-netns.c @@ -262,9 +262,7 @@ _stack_push(GArray *netns_stack, NMPNetns *netns, int ns_types) nm_assert(NM_FLAGS_ANY(ns_types, _CLONE_NS_ALL)); nm_assert(!NM_FLAGS_ANY(ns_types, ~_CLONE_NS_ALL)); - g_array_set_size(netns_stack, netns_stack->len + 1); - - info = &g_array_index(netns_stack, NetnsInfo, (netns_stack->len - 1)); + info = nm_g_array_append_new(netns_stack, NetnsInfo); *info = (NetnsInfo){ .netns = g_object_ref(netns), .ns_types = ns_types,