all: use nm_g_array_append_new() at various places

This commit is contained in:
Thomas Haller 2022-09-08 12:57:10 +02:00
parent ef8fa9f6aa
commit 2c8dcbeaf9
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
6 changed files with 14 additions and 20 deletions

View file

@ -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;
}

View file

@ -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));

View file

@ -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];

View file

@ -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,

View file

@ -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;

View file

@ -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,