From 2c8dcbeaf995b0f5eb00d6f8626ee0cb64e7abff Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Sep 2022 12:57:10 +0200 Subject: [PATCH 1/4] all: use nm_g_array_append_new() at various places --- src/core/nm-policy.c | 5 ++--- src/core/platform/nm-fake-platform.c | 3 +-- src/libnm-core-impl/nm-setting.c | 3 +-- src/libnm-core-impl/nm-utils.c | 8 ++++---- src/libnm-platform/nm-linux-platform.c | 11 +++++------ src/libnm-platform/nmp-netns.c | 4 +--- 6 files changed, 14 insertions(+), 20 deletions(-) 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, From 07b32d5d225f63e2fe87f20e101dc3199e106423 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Sep 2022 11:52:49 +0200 Subject: [PATCH 2/4] glib-aux: add nm_g_array_index() macro and improve nm_g_array_index_p() macros Add nm_g_array_index() as a replacement for g_array_index(). The value of nm_g_array_index(), nm_g_array_index_p(), nm_g_array_first() and nm_g_array_last() is that they add nm_assert() checks for valid parameters. nm_g_array_{first,last}() now returns an lvalue and not a pointer. As such, they are just shorthands for nm_g_array_index() at index 0 and len-1, respectively. `nm_g_array_index_p(arr, Type, idx)` is almost the same as `&nm_g_array_index(arr, Type, idx)`. The only difference (and why the former variant exists), is that nm_g_array_index_p() allows to get a pointer one after the end. This means, this is correct and valid to do: // arr->len might be zero arr = nm_g_array_index_p(arr, Type, 0); for (i = 0; i < arr->len; i++, arr++) ... ptr = nm_g_array_index_p(arr, Type, 0); end = nm_g_array_index_p(arr, Type, arr->len); for (; ptr < end; ptr++) ... This would not be valid to do with nm_g_array_{index,first,last}(). Also fix supporting "const GArray *arr" parameter. Of course, the function casts the constness away. Technically, that matches the fact that arr->data is also not a const pointer. In practice, we might want to propagate the constness of the container to the constness of the element lookup. While doable, that is not implemented. --- src/core/nm-core-utils.c | 2 +- src/libnm-glib-aux/nm-shared-utils.h | 84 +++++++++++-------- .../tests/test-shared-general.c | 33 ++++++++ 3 files changed, 85 insertions(+), 34 deletions(-) diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index 0d325f0fe1..f1409c7d35 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -3022,7 +3022,7 @@ nmtst_utils_host_id_pop(void) &host_id_static, h, nmtst_host_id_stack->len == 0u ? nmtst_host_id_static_0 - : nm_g_array_last(nmtst_host_id_stack, HostIdData))) + : &nm_g_array_last(nmtst_host_id_stack, HostIdData))) g_assert_not_reached(); } diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 892d0d3012..caf275f454 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -1866,43 +1866,61 @@ nm_g_array_unref(GArray *arr) g_array_unref(arr); } -#define nm_g_array_first(arr, Type) \ - ({ \ - GArray *const _arr = (arr); \ - \ - nm_assert(_arr); \ - nm_assert(sizeof(Type) == g_array_get_element_size(_arr)); \ - nm_assert(_arr->len > 0); \ - \ - &g_array_index(arr, Type, 0); \ - }) - -#define nm_g_array_last(arr, Type) \ - ({ \ - GArray *const _arr = (arr); \ - \ - nm_assert(_arr); \ - nm_assert(sizeof(Type) == g_array_get_element_size(_arr)); \ - nm_assert(_arr->len > 0); \ - \ - &g_array_index(arr, Type, _arr->len - 1u); \ - }) - /* Similar to g_array_index(). The differences are * - this does nm_assert() checks that the arguments are valid. - * - returns a pointer to the element. */ -#define nm_g_array_index_p(arr, Type, idx) \ - ({ \ - GArray *const _arr_55 = (arr); \ - const guint _idx_55 = (idx); \ - \ - nm_assert(_arr_55); \ - nm_assert(sizeof(Type) == g_array_get_element_size(_arr_55)); \ - nm_assert(_idx_55 < _arr_55->len); \ - \ - &g_array_index(_arr_55, Type, _idx_55); \ + * - returns a pointer to the element. + * - it asserts that @idx is <= arr->len. That is, it allows + * to get a pointer after the data, of course, you are not + * allowed to dereference in that case. */ +#define nm_g_array_index_p(arr, Type, idx) \ + ({ \ + const GArray *const _arr_55 = (arr); \ + const guint _idx_55 = (idx); \ + \ + nm_assert(_arr_55); \ + nm_assert(sizeof(Type) == g_array_get_element_size((GArray *) _arr_55)); \ + nm_assert(_idx_55 <= _arr_55->len); \ + \ + /* If arr->len is zero, arr->data might be NULL. The macro + * allows to access at index [arr->len] (one past the data). + * We need to take care of undefined behavior, but (NULL + 0) + * should work mostly fine for us. */ \ + ((Type *) ((gpointer) _arr_55->data)) + (_idx_55); \ }) +/* Very similar to g_array_index(). + * - nm_assert() that arguments are valid. + * - returns an lvalue to the element. + * - similar to nm_g_array_index_p(), but dereferences the pointer. + * - one difference to nm_g_array_index_p() is that it @idx MUST be + * smaller than arr->len (unlike nm_g_array_index_p() which allows + * access one element past the buffer. */ +#define nm_g_array_index(arr, Type, idx) \ + (*({ \ + const GArray *const _arr_55 = (arr); \ + const guint _idx_55 = (idx); \ + \ + nm_assert(_arr_55); \ + nm_assert(sizeof(Type) == g_array_get_element_size((GArray *) _arr_55)); \ + nm_assert(_idx_55 < _arr_55->len); \ + \ + &g_array_index((GArray *) _arr_55, Type, _idx_55); \ + })) + +#define nm_g_array_first(arr, Type) nm_g_array_index(arr, Type, 0) + +/* Same as g_array_index(arr, Type, arr->len-1). */ +#define nm_g_array_last(arr, Type) \ + (*({ \ + const GArray *const _arr = (arr); \ + \ + nm_assert(_arr); \ + nm_assert(sizeof(Type) == g_array_get_element_size((GArray *) _arr)); \ + nm_assert(_arr->len > 0); \ + \ + &g_array_index((GArray *) arr, Type, _arr->len - 1u); \ + })) + #define nm_g_array_append_new(arr, Type) \ ({ \ GArray *const _arr = (arr); \ diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index a49bbe0a20..b7fde16bf0 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -2218,6 +2218,38 @@ test_inet_utils(void) /*****************************************************************************/ +static void +test_garray(void) +{ + gs_unref_array GArray *arr = NULL; + int v; + + arr = g_array_new(FALSE, FALSE, sizeof(int)); + g_assert(nm_g_array_index_p(arr, int, 0) == (gpointer) arr->data); + + v = 1; + g_array_append_val(arr, v); + g_assert(nm_g_array_index_p(arr, int, 0) == (gpointer) arr->data); + g_assert(nm_g_array_index_p(arr, int, 1) == ((int *) ((gpointer) arr->data)) + 1); + g_assert(&nm_g_array_index(arr, int, 0) == (gpointer) arr->data); + g_assert(&nm_g_array_first(arr, int) == (gpointer) arr->data); + g_assert(&nm_g_array_last(arr, int) == (gpointer) arr->data); + g_assert(nm_g_array_index(arr, int, 0) == 1); + + v = 2; + g_array_append_val(arr, v); + g_assert(nm_g_array_index_p(arr, int, 0) == (gpointer) arr->data); + g_assert(nm_g_array_index_p(arr, int, 1) == ((int *) ((gpointer) arr->data)) + 1); + g_assert(nm_g_array_index_p(arr, int, 2) == ((int *) ((gpointer) arr->data)) + 2); + g_assert(&nm_g_array_index(arr, int, 0) == (gpointer) arr->data); + g_assert(&nm_g_array_first(arr, int) == (gpointer) arr->data); + g_assert(&nm_g_array_last(arr, int) == ((int *) ((gpointer) arr->data)) + 1); + g_assert(nm_g_array_index(arr, int, 0) == 1); + g_assert(nm_g_array_index(arr, int, 1) == 2); +} + +/*****************************************************************************/ + NMTST_DEFINE(); int @@ -2263,6 +2295,7 @@ main(int argc, char **argv) g_test_add_func("/general/test_path_simplify", test_path_simplify); g_test_add_func("/general/test_hostname_is_valid", test_hostname_is_valid); g_test_add_func("/general/test_inet_utils", test_inet_utils); + g_test_add_func("/general/test_garray", test_garray); return g_test_run(); } From ffd8baa49fd5310501cacabb939445b0aef900cf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Sep 2022 12:05:56 +0200 Subject: [PATCH 3/4] all: use nm_g_array_{index,first,last,index_p}() instead of g_array_index() These variants provide additional nm_assert() checks, and are thus preferable. Note that we cannot just blindly replace &g_array_index() with &nm_g_array_index(), because the latter would not allow getting a pointer at index [arr->len]. That might be a valid (though uncommon) usecase. The correct replacement of &g_array_index() is thus nm_g_array_index_p(). I checked the code manually and replaced uses of nm_g_array_index_p() with &nm_g_array_index(), if that was a safe thing to do. The latter seems preferable, because it is familar to &g_array_index(). --- src/core/devices/nm-device-wireguard.c | 2 +- src/core/devices/ovs/nm-ovsdb.c | 6 +-- src/core/devices/wwan/nm-modem-broadband.c | 2 +- src/core/dhcp/nm-dhcp-client.c | 2 +- src/core/dns/nm-dns-systemd-resolved.c | 4 +- src/core/ndisc/nm-fake-ndisc.c | 8 +-- src/core/ndisc/nm-lndp-ndisc.c | 6 +-- src/core/ndisc/nm-ndisc.c | 51 ++++++++++--------- src/core/nm-core-utils.c | 8 +-- src/core/nm-l3-config-data.c | 8 +-- src/core/nm-l3cfg.c | 2 +- src/core/nm-manager.c | 2 +- src/core/nm-policy.c | 16 +++--- src/core/platform/nm-fake-platform.c | 4 +- src/core/platform/tests/test-address.c | 4 +- src/core/platform/tests/test-cleanup.c | 2 +- src/core/platform/tests/test-link.c | 2 +- src/core/tests/test-core-with-expect.c | 14 ++--- src/libnm-core-impl/nm-setting-connection.c | 12 ++--- src/libnm-core-impl/nm-setting-ip-config.c | 4 +- src/libnm-core-impl/nm-setting-wired.c | 8 +-- src/libnm-core-impl/nm-setting-wireless.c | 8 +-- src/libnm-core-impl/nm-setting.c | 6 +-- src/libnm-core-impl/nm-vpn-plugin-info.c | 2 +- src/libnm-core-impl/tests/test-setting.c | 2 +- src/libnm-glib-aux/nm-shared-utils.h | 2 +- src/libnm-glib-aux/nm-test-utils.h | 2 +- src/libnm-platform/nm-linux-platform.c | 10 ++-- src/libnm-platform/nmp-global-tracker.c | 6 +-- src/libnm-platform/nmp-netns.c | 10 ++-- src/libnmc-setting/nm-meta-setting-access.c | 2 +- src/nm-initrd-generator/nm-initrd-generator.c | 4 +- src/nmcli/connections.c | 8 +-- src/nmcli/devices.c | 2 +- src/nmcli/utils.c | 30 ++++++----- 35 files changed, 133 insertions(+), 128 deletions(-) diff --git a/src/core/devices/nm-device-wireguard.c b/src/core/devices/nm-device-wireguard.c index 62be29f106..2eb28fd94e 100644 --- a/src/core/devices/nm-device-wireguard.c +++ b/src/core/devices/nm-device-wireguard.c @@ -1197,7 +1197,7 @@ skip: nm_assert(plp->_construct_idx_start < plp->_construct_idx_end); l = plp->_construct_idx_end - plp->_construct_idx_start; plp->allowed_ips = - &g_array_index(allowed_ips, NMPWireGuardAllowedIP, plp->_construct_idx_start); + &nm_g_array_index(allowed_ips, NMPWireGuardAllowedIP, plp->_construct_idx_start); plp->allowed_ips_len = l; } } diff --git a/src/core/devices/ovs/nm-ovsdb.c b/src/core/devices/ovs/nm-ovsdb.c index c1f0886d41..0477efb08d 100644 --- a/src/core/devices/ovs/nm-ovsdb.c +++ b/src/core/devices/ovs/nm-ovsdb.c @@ -1539,8 +1539,8 @@ _external_ids_equal(const GArray *arr1, const GArray *arr2) if (n != nm_g_array_len(arr2)) return FALSE; for (i = 0; i < n; i++) { - const NMUtilsNamedValue *n1 = &g_array_index(arr1, NMUtilsNamedValue, i); - const NMUtilsNamedValue *n2 = &g_array_index(arr2, NMUtilsNamedValue, i); + const NMUtilsNamedValue *n1 = &nm_g_array_index(arr1, NMUtilsNamedValue, i); + const NMUtilsNamedValue *n2 = &nm_g_array_index(arr2, NMUtilsNamedValue, i); if (!nm_streq0(n1->name, n2->name)) return FALSE; @@ -1562,7 +1562,7 @@ _external_ids_to_string(const GArray *arr) strbuf = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); nm_str_buf_append(&strbuf, "["); for (i = 0; i < arr->len; i++) { - const NMUtilsNamedValue *n = &g_array_index(arr, NMUtilsNamedValue, i); + const NMUtilsNamedValue *n = &nm_g_array_index(arr, NMUtilsNamedValue, i); if (i > 0) nm_str_buf_append_c(&strbuf, ','); diff --git a/src/core/devices/wwan/nm-modem-broadband.c b/src/core/devices/wwan/nm-modem-broadband.c index a4078be842..d550283a3e 100644 --- a/src/core/devices/wwan/nm-modem-broadband.c +++ b/src/core/devices/wwan/nm-modem-broadband.c @@ -636,7 +636,7 @@ connect_context_step(NMModemBroadband *self) if (ctx->ip_types_i < ctx->ip_types->len) { NMModemIPType current; - current = g_array_index(ctx->ip_types, NMModemIPType, ctx->ip_types_i); + current = nm_g_array_index(ctx->ip_types, NMModemIPType, ctx->ip_types_i); if (current == NM_MODEM_IP_TYPE_IPV4) mm_simple_connect_properties_set_ip_type(ctx->connect_properties, diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 68246280e3..bd67be1b86 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -438,7 +438,7 @@ _acd_complete_on_idle_cb(gpointer user_data) } #define _acd_reglist_data_get(priv, idx) \ - nm_g_array_index_p((priv)->v4.acd.reglist, AcdRegListData, (idx)) + (&nm_g_array_index((priv)->v4.acd.reglist, AcdRegListData, (idx))) static guint _acd_reglist_data_find(NMDhcpClientPrivate *priv, in_addr_t addr_needle) diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index 5a22fa25ca..06e524302d 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -759,7 +759,7 @@ update(NMDnsPlugin *plugin, if (dirty_array) { g_array_sort_with_data(dirty_array, nm_cmp_int2ptr_p_with_data, NULL); for (i = 0; i < dirty_array->len; i++) { - int ifindex = g_array_index(dirty_array, int, i); + int ifindex = nm_g_array_index(dirty_array, int, i); InterfaceConfig ic; _LOGT("clear previously configured ifindex %d", ifindex); @@ -968,7 +968,7 @@ _resolve_handle_call_cb(GObject *source, GAsyncResult *result, gpointer user_dat g_variant_iter_free(v_names_iter); _resolve_complete(handle, - &g_array_index(v_names, NMDnsSystemdResolvedAddressResult, 0), + nm_g_array_index_p(v_names, NMDnsSystemdResolvedAddressResult, 0), v_names->len, v_flags, NULL); diff --git a/src/core/ndisc/nm-fake-ndisc.c b/src/core/ndisc/nm-fake-ndisc.c index 5aea273e24..5811e480b6 100644 --- a/src/core/ndisc/nm-fake-ndisc.c +++ b/src/core/ndisc/nm-fake-ndisc.c @@ -247,14 +247,14 @@ receive_ra(gpointer user_data) } for (i = 0; i < ra->gateways->len; i++) { - const NMNDiscGateway *item = &g_array_index(ra->gateways, NMNDiscGateway, i); + const NMNDiscGateway *item = &nm_g_array_index(ra->gateways, NMNDiscGateway, i); if (nm_ndisc_add_gateway(ndisc, item, now_msec)) changed |= NM_NDISC_CONFIG_GATEWAYS; } for (i = 0; i < ra->prefixes->len; i++) { - FakePrefix *item = &g_array_index(ra->prefixes, FakePrefix, i); + FakePrefix *item = &nm_g_array_index(ra->prefixes, FakePrefix, i); const NMNDiscRoute route = { .network = item->network, .plen = item->plen, @@ -282,14 +282,14 @@ receive_ra(gpointer user_data) } for (i = 0; i < ra->dns_servers->len; i++) { - const NMNDiscDNSServer *item = &g_array_index(ra->dns_servers, NMNDiscDNSServer, i); + const NMNDiscDNSServer *item = &nm_g_array_index(ra->dns_servers, NMNDiscDNSServer, i); if (nm_ndisc_add_dns_server(ndisc, item, now_msec)) changed |= NM_NDISC_CONFIG_DNS_SERVERS; } for (i = 0; i < ra->dns_domains->len; i++) { - const NMNDiscDNSDomain *item = &g_array_index(ra->dns_domains, NMNDiscDNSDomain, i); + const NMNDiscDNSDomain *item = &nm_g_array_index(ra->dns_domains, NMNDiscDNSDomain, i); if (nm_ndisc_add_dns_domain(ndisc, item, now_msec)) changed |= NM_NDISC_CONFIG_DNS_DOMAINS; diff --git a/src/core/ndisc/nm-lndp-ndisc.c b/src/core/ndisc/nm-lndp-ndisc.c index 38eacd2a42..39a7e2a8d5 100644 --- a/src/core/ndisc/nm-lndp-ndisc.c +++ b/src/core/ndisc/nm-lndp-ndisc.c @@ -413,7 +413,7 @@ send_ra(NMNDisc *ndisc, GError **error) /* The device let us know about all addresses that the device got * whose prefixes are suitable for delegating. Let's announce them. */ for (i = 0; i < rdata->addresses->len; i++) { - const NMNDiscAddress *address = &g_array_index(rdata->addresses, NMNDiscAddress, i); + const NMNDiscAddress *address = &nm_g_array_index(rdata->addresses, NMNDiscAddress, i); struct nd_opt_prefix_info *prefix; prefix = _ndp_msg_add_option(msg, sizeof(*prefix)); @@ -458,7 +458,7 @@ send_ra(NMNDisc *ndisc, GError **error) for (i = 0; i < rdata->dns_servers->len; i++) { const NMNDiscDNSServer *dns_server = - &g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); + &nm_g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); option->addrs[i] = dns_server->address; } @@ -474,7 +474,7 @@ dns_servers_done: for (i = 0; i < rdata->dns_domains->len; i++) { const NMNDiscDNSDomain *dns_domain = - &g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); + &nm_g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); const char *domain = dns_domain->domain; gsize domain_l; gsize n_reserved; diff --git a/src/core/ndisc/nm-ndisc.c b/src/core/ndisc/nm-ndisc.c index ec5a83c622..0520aaebab 100644 --- a/src/core/ndisc/nm-ndisc.c +++ b/src/core/ndisc/nm-ndisc.c @@ -324,11 +324,11 @@ _ASSERT_data_gateways(const NMNDiscDataInternal *data) return; for (i = 0; i < data->gateways->len; i++) { - const NMNDiscGateway *item = &g_array_index(data->gateways, NMNDiscGateway, i); + const NMNDiscGateway *item = &nm_g_array_index(data->gateways, NMNDiscGateway, i); nm_assert(!IN6_IS_ADDR_UNSPECIFIED(&item->address)); for (j = 0; j < i; j++) { - const NMNDiscGateway *item2 = &g_array_index(data->gateways, NMNDiscGateway, j); + const NMNDiscGateway *item2 = &nm_g_array_index(data->gateways, NMNDiscGateway, j); nm_assert(!IN6_ARE_ADDR_EQUAL(&item->address, &item2->address)); } @@ -402,7 +402,7 @@ nm_ndisc_add_gateway(NMNDisc *ndisc, const NMNDiscGateway *new_item, gint64 now_ guint insert_idx = G_MAXUINT; for (i = 0; i < rdata->gateways->len;) { - NMNDiscGateway *item = &g_array_index(rdata->gateways, NMNDiscGateway, i); + NMNDiscGateway *item = &nm_g_array_index(rdata->gateways, NMNDiscGateway, i); if (IN6_ARE_ADDR_EQUAL(&item->address, &new_item->address)) { if (new_item->expiry_msec <= now_msec) { @@ -519,7 +519,7 @@ nm_ndisc_add_address(NMNDisc *ndisc, nm_assert((!!from_ra) == (now_msec > 0)); for (i = 0; i < rdata->addresses->len; i++) { - NMNDiscAddress *item = &g_array_index(rdata->addresses, NMNDiscAddress, i); + NMNDiscAddress *item = &nm_g_array_index(rdata->addresses, NMNDiscAddress, i); if (from_ra) { /* RFC4862 5.5.3.d, we find an existing address with the same prefix. @@ -651,7 +651,7 @@ nm_ndisc_add_route(NMNDisc *ndisc, const NMNDiscRoute *new_item, gint64 now_msec rdata = &priv->rdata; for (i = 0; i < rdata->routes->len;) { - NMNDiscRoute *item = &g_array_index(rdata->routes, NMNDiscRoute, i); + NMNDiscRoute *item = &nm_g_array_index(rdata->routes, NMNDiscRoute, i); if (IN6_ARE_ADDR_EQUAL(&item->network, &new_item->network) && item->plen == new_item->plen) { @@ -707,7 +707,7 @@ nm_ndisc_add_dns_server(NMNDisc *ndisc, const NMNDiscDNSServer *new_item, gint64 rdata = &priv->rdata; for (i = 0; i < rdata->dns_servers->len; i++) { - NMNDiscDNSServer *item = &g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); + NMNDiscDNSServer *item = &nm_g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); if (IN6_ARE_ADDR_EQUAL(&item->address, &new_item->address)) { if (new_item->expiry_msec <= now_msec) { @@ -746,7 +746,7 @@ nm_ndisc_add_dns_domain(NMNDisc *ndisc, const NMNDiscDNSDomain *new_item, gint64 rdata = &priv->rdata; for (i = 0; i < rdata->dns_domains->len; i++) { - item = &g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); + item = &nm_g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); if (nm_streq(item->domain, new_item->domain)) { if (new_item->expiry_msec <= now_msec) { @@ -1230,7 +1230,7 @@ nm_ndisc_dad_failed(NMNDisc *ndisc, const struct in6_addr *address, gboolean emi rdata = &NM_NDISC_GET_PRIVATE(ndisc)->rdata; for (i = 0; i < rdata->addresses->len;) { - NMNDiscAddress *item = &g_array_index(rdata->addresses, NMNDiscAddress, i); + NMNDiscAddress *item = &nm_g_array_index(rdata->addresses, NMNDiscAddress, i); if (IN6_ARE_ADDR_EQUAL(&item->address, address)) { char sbuf[NM_INET_ADDRSTRLEN]; @@ -1303,7 +1303,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) _LOGD(" retrans timer : %u", (guint) rdata->public.retrans_timer_ms); for (i = 0; i < rdata->gateways->len; i++) { - const NMNDiscGateway *gateway = &g_array_index(rdata->gateways, NMNDiscGateway, i); + const NMNDiscGateway *gateway = &nm_g_array_index(rdata->gateways, NMNDiscGateway, i); _LOGD(" gateway %s pref %s exp %s", nm_inet6_ntop(&gateway->address, addrstr), @@ -1311,14 +1311,14 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) get_exp(str_exp, now_msec, gateway)); } for (i = 0; i < rdata->addresses->len; i++) { - const NMNDiscAddress *address = &g_array_index(rdata->addresses, NMNDiscAddress, i); + const NMNDiscAddress *address = &nm_g_array_index(rdata->addresses, NMNDiscAddress, i); _LOGD(" address %s exp %s", nm_inet6_ntop(&address->address, addrstr), get_exp(str_exp, now_msec, address)); } for (i = 0; i < rdata->routes->len; i++) { - const NMNDiscRoute *route = &g_array_index(rdata->routes, NMNDiscRoute, i); + const NMNDiscRoute *route = &nm_g_array_index(rdata->routes, NMNDiscRoute, i); char sbuf[NM_INET_ADDRSTRLEN]; _LOGD(" route %s/%u via %s pref %s exp %s", @@ -1330,7 +1330,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) } for (i = 0; i < rdata->dns_servers->len; i++) { const NMNDiscDNSServer *dns_server = - &g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); + &nm_g_array_index(rdata->dns_servers, NMNDiscDNSServer, i); _LOGD(" dns_server %s exp %s", nm_inet6_ntop(&dns_server->address, addrstr), @@ -1338,7 +1338,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed) } for (i = 0; i < rdata->dns_domains->len; i++) { const NMNDiscDNSDomain *dns_domain = - &g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); + &nm_g_array_index(rdata->dns_domains, NMNDiscDNSDomain, i); _LOGD(" dns_domain %s exp %s", dns_domain->domain, get_exp(str_exp, now_msec, dns_domain)); } @@ -1370,7 +1370,7 @@ clean_gateways(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint6 if (rdata->gateways->len == 0) return; - arr = &g_array_index(rdata->gateways, NMNDiscGateway, 0); + arr = &nm_g_array_index(rdata->gateways, NMNDiscGateway, 0); for (i = 0, j = 0; i < rdata->gateways->len; i++) { if (!expiry_next(now_msec, arr[i].expiry_msec, next_msec)) @@ -1403,7 +1403,7 @@ clean_addresses(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint if (rdata->addresses->len == 0) return; - arr = &g_array_index(rdata->addresses, NMNDiscAddress, 0); + arr = &nm_g_array_index(rdata->addresses, NMNDiscAddress, 0); for (i = 0, j = 0; i < rdata->addresses->len; i++) { if (!expiry_next(now_msec, arr[i].expiry_msec, next_msec)) @@ -1433,7 +1433,7 @@ clean_routes(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gint64 if (rdata->routes->len == 0) return; - arr = &g_array_index(rdata->routes, NMNDiscRoute, 0); + arr = &nm_g_array_index(rdata->routes, NMNDiscRoute, 0); for (i = 0, j = 0; i < rdata->routes->len; i++) { if (!expiry_next(now_msec, arr[i].expiry_msec, next_msec)) @@ -1463,7 +1463,7 @@ clean_dns_servers(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gi if (rdata->dns_servers->len == 0) return; - arr = &g_array_index(rdata->dns_servers, NMNDiscDNSServer, 0); + arr = &nm_g_array_index(rdata->dns_servers, NMNDiscDNSServer, 0); for (i = 0, j = 0; i < rdata->dns_servers->len; i++) { if (!expiry_next(now_msec, arr[i].expiry_msec, next_msec)) @@ -1493,7 +1493,7 @@ clean_dns_domains(NMNDisc *ndisc, gint64 now_msec, NMNDiscConfigMap *changed, gi if (rdata->dns_domains->len == 0) return; - arr = &g_array_index(rdata->dns_domains, NMNDiscDNSDomain, 0); + arr = &nm_g_array_index(rdata->dns_domains, NMNDiscDNSDomain, 0); for (i = 0, j = 0; i < rdata->dns_domains->len; i++) { if (!expiry_next(now_msec, arr[i].expiry_msec, next_msec)) @@ -1602,34 +1602,35 @@ calc_pre_expiry_rs_msec(NMNDisc *ndisc) _calc_pre_expiry_rs_msec_worker( &expiry_msec, priv->last_rs_msec, - g_array_index(rdata->gateways, NMNDiscGateway, i).expiry_msec); + nm_g_array_index(rdata->gateways, NMNDiscGateway, i).expiry_msec); } for (i = 0; i < rdata->addresses->len; i++) { _calc_pre_expiry_rs_msec_worker( &expiry_msec, priv->last_rs_msec, - g_array_index(rdata->addresses, NMNDiscAddress, 0).expiry_msec); + nm_g_array_index(rdata->addresses, NMNDiscAddress, 0).expiry_msec); } for (i = 0; i < rdata->routes->len; i++) { - _calc_pre_expiry_rs_msec_worker(&expiry_msec, - priv->last_rs_msec, - g_array_index(rdata->routes, NMNDiscRoute, 0).expiry_msec); + _calc_pre_expiry_rs_msec_worker( + &expiry_msec, + priv->last_rs_msec, + nm_g_array_index(rdata->routes, NMNDiscRoute, 0).expiry_msec); } for (i = 0; i < rdata->dns_servers->len; i++) { _calc_pre_expiry_rs_msec_worker( &expiry_msec, priv->last_rs_msec, - g_array_index(rdata->dns_servers, NMNDiscDNSServer, 0).expiry_msec); + nm_g_array_index(rdata->dns_servers, NMNDiscDNSServer, 0).expiry_msec); } for (i = 0; i < rdata->dns_domains->len; i++) { _calc_pre_expiry_rs_msec_worker( &expiry_msec, priv->last_rs_msec, - g_array_index(rdata->dns_domains, NMNDiscDNSDomain, 0).expiry_msec); + nm_g_array_index(rdata->dns_domains, NMNDiscDNSDomain, 0).expiry_msec); } return expiry_msec - solicit_retransmit_time_jitter(NM_NDISC_PRE_EXPIRY_TIME_MSEC); diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index f1409c7d35..3d6790759d 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -2333,14 +2333,14 @@ nm_utils_log_connection_diff(NMConnection *connection, for (i = 0; i < sorted_hashes->len; i++) { LogConnectionSettingData *setting_data = - &g_array_index(sorted_hashes, LogConnectionSettingData, i); + &nm_g_array_index(sorted_hashes, LogConnectionSettingData, i); _log_connection_sort_names(setting_data, sorted_names); print_setting_header = TRUE; for (j = 0; j < sorted_names->len; j++) { char *str_conn, *str_diff; LogConnectionSettingItem *item = - &g_array_index(sorted_names, LogConnectionSettingItem, j); + &nm_g_array_index(sorted_names, LogConnectionSettingItem, j); str_conn = (item->diff_result & NM_SETTING_DIFF_RESULT_IN_A) ? _log_connection_get_property(setting_data->setting, item->item_name) @@ -3013,7 +3013,7 @@ nmtst_utils_host_id_pop(void) nm_log_dbg(LOGD_CORE, "nmtst: host-id pop"); - h = &g_array_index(nmtst_host_id_stack, HostIdData, nmtst_host_id_stack->len - 1); + h = &nm_g_array_index(nmtst_host_id_stack, HostIdData, nmtst_host_id_stack->len - 1); g_free((char *) h->host_id); g_array_set_size(nmtst_host_id_stack, nmtst_host_id_stack->len - 1u); @@ -4331,7 +4331,7 @@ skip: result = g_new(char *, paths->len + 1); for (i = 0; i < paths->len; i++) - result[i] = g_array_index(paths, struct plugin_info, i).path; + result[i] = nm_g_array_index(paths, struct plugin_info, i).path; result[i] = NULL; g_array_free(paths, TRUE); diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 2c51fd0257..3d4aa14243 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -276,8 +276,8 @@ _garray_inaddr_at(GArray *arr, gboolean IS_IPv4, guint idx) nm_assert(idx < arr->len); if (IS_IPv4) - return &g_array_index(arr, in_addr_t, idx); - return &g_array_index(arr, struct in6_addr, idx); + return &nm_g_array_index(arr, in_addr_t, idx); + return &nm_g_array_index(arr, struct in6_addr, idx); } static gboolean @@ -514,12 +514,12 @@ nm_l3_config_data_log(const NML3ConfigData *self, for (i = 0; i < nm_g_array_len(self->wins); i++) { _L("wins[%u]: %s", i, - nm_inet4_ntop(g_array_index(self->wins, in_addr_t, i), sbuf_addr)); + nm_inet4_ntop(nm_g_array_index(self->wins, in_addr_t, i), sbuf_addr)); } for (i = 0; i < nm_g_array_len(self->nis_servers); i++) { _L("nis-server[%u]: %s", i, - nm_inet4_ntop(g_array_index(self->nis_servers, in_addr_t, i), sbuf_addr)); + nm_inet4_ntop(nm_g_array_index(self->nis_servers, in_addr_t, i), sbuf_addr)); } if (self->nis_domain) _L("nis-domain: %s", self->nis_domain->str); diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index f2ed0f63fb..a4f63483bb 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -3144,7 +3144,7 @@ nm_l3cfg_commit_on_idle_is_scheduled(NML3Cfg *self) /*****************************************************************************/ #define _l3_config_datas_at(l3_config_datas, idx) \ - (&g_array_index((l3_config_datas), L3ConfigData, (idx))) + (&nm_g_array_index((l3_config_datas), L3ConfigData, (idx))) static gssize _l3_config_datas_find_next(GArray *l3_config_datas, diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index df890cdb6f..7cbca24ef4 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -7902,7 +7902,7 @@ nm_manager_set_capability(NMManager *self, NMCapability cap) priv = NM_MANAGER_GET_PRIVATE(self); - idx = nm_utils_array_find_binary_search(&g_array_index(priv->capabilities, guint32, 0), + idx = nm_utils_array_find_binary_search(nm_g_array_index_p(priv->capabilities, guint32, 0), sizeof(guint32), priv->capabilities->len, &cap_i, diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index f13282c482..b97b28d64b 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -187,7 +187,7 @@ expire_ip6_delegations(NMPolicy *self) guint i; for (i = 0; i < priv->ip6_prefix_delegations->len; i++) { - delegation = &g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); + delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); if (delegation->prefix.timestamp + delegation->prefix.lifetime < now) g_array_remove_index_fast(priv->ip6_prefix_delegations, i); } @@ -267,7 +267,7 @@ ip6_subnet_from_device(NMPolicy *self, NMDevice *from_device, NMDevice *device) expire_ip6_delegations(self); for (i = 0; i < priv->ip6_prefix_delegations->len; i++) { - delegation = &g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); + delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); if (delegation->device != from_device) continue; @@ -295,7 +295,7 @@ ip6_remove_device_prefix_delegations(NMPolicy *self, NMDevice *device) guint i; for (i = 0; i < priv->ip6_prefix_delegations->len; i++) { - delegation = &g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); + delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); if (delegation->device == device) g_array_remove_index_fast(priv->ip6_prefix_delegations, i); } @@ -324,7 +324,7 @@ device_ip6_prefix_delegated(NMDevice *device, for (i = 0; i < priv->ip6_prefix_delegations->len; i++) { /* Look for an already known prefix to update. */ - delegation = &g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); + delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i); if (IN6_ARE_ADDR_EQUAL(&delegation->prefix.address, &prefix->address)) break; } @@ -769,10 +769,10 @@ build_device_hostname_infos(NMPolicy *self) g_array_sort(array, device_hostname_info_compare); - info0 = &g_array_index(array, DeviceHostnameInfo, 0); + info0 = &nm_g_array_index(array, DeviceHostnameInfo, 0); if (info0->priority < 0) { for (i = 1; i < array->len; i++) { - const DeviceHostnameInfo *info = &g_array_index(array, DeviceHostnameInfo, i); + const DeviceHostnameInfo *info = &nm_g_array_index(array, DeviceHostnameInfo, i); if (info->priority > info0->priority) { g_array_set_size(array, i); @@ -863,7 +863,7 @@ update_system_hostname(NMPolicy *self, const char *msg) if (infos && _LOGT_ENABLED(LOGD_DNS)) { _LOGT(LOGD_DNS, "device hostname info:"); for (i = 0; i < infos->len; i++) { - info = &g_array_index(infos, DeviceHostnameInfo, i); + info = &nm_g_array_index(infos, DeviceHostnameInfo, i); _LOGT(LOGD_DNS, " - prio:%5d ipv%c%s %s %s dev:%s", info->priority, @@ -876,7 +876,7 @@ update_system_hostname(NMPolicy *self, const char *msg) } for (i = 0; infos && i < infos->len; i++) { - info = &g_array_index(infos, DeviceHostnameInfo, i); + info = &nm_g_array_index(infos, DeviceHostnameInfo, i); addr_family = info->IS_IPv4 ? AF_INET : AF_INET6; g_signal_handlers_disconnect_by_func(info->device, device_dns_lookup_done, self); diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c index 70c8664666..49aa07e0d1 100644 --- a/src/core/platform/nm-fake-platform.c +++ b/src/core/platform/nm-fake-platform.c @@ -170,7 +170,7 @@ link_get(NMPlatform *platform, int ifindex) if (idx >= priv->links->len) goto not_found; - device = &g_array_index(priv->links, NMFakePlatformLink, idx); + device = &nm_g_array_index(priv->links, NMFakePlatformLink, idx); if (!device->obj) goto not_found; @@ -1291,7 +1291,7 @@ finalize(GObject *object) g_hash_table_unref(priv->options); for (i = 0; i < priv->links->len; i++) { - NMFakePlatformLink *device = &g_array_index(priv->links, NMFakePlatformLink, i); + NMFakePlatformLink *device = &nm_g_array_index(priv->links, NMFakePlatformLink, i); nm_clear_pointer(&device->obj, nmp_object_unref); } diff --git a/src/core/platform/tests/test-address.c b/src/core/platform/tests/test-address.c index 700891e88d..cdee042860 100644 --- a/src/core/platform/tests/test-address.c +++ b/src/core/platform/tests/test-address.c @@ -118,7 +118,7 @@ test_ip4_address_general(void) addresses = nmtstp_platform_ip4_address_get_all(NM_PLATFORM_GET, ifindex); g_assert(addresses); g_assert_cmpint(addresses->len, ==, 1); - address = &g_array_index(addresses, NMPlatformIP4Address, 0); + address = &nm_g_array_index(addresses, NMPlatformIP4Address, 0); g_assert_cmpint(address->ifindex, ==, ifindex); g_assert_cmphex(address->address, ==, addr); g_assert_cmphex(address->peer_address, ==, addr); @@ -193,7 +193,7 @@ test_ip6_address_general(void) addresses = nmtstp_platform_ip6_address_get_all(NM_PLATFORM_GET, ifindex); g_assert(addresses); g_assert_cmpint(addresses->len, ==, 1); - address = &g_array_index(addresses, NMPlatformIP6Address, 0); + address = &nm_g_array_index(addresses, NMPlatformIP6Address, 0); g_assert_cmpint(address->ifindex, ==, ifindex); g_assert(!memcmp(&address->address, &addr, sizeof(addr))); g_assert_cmpint(address->plen, ==, IP6_PLEN); diff --git a/src/core/platform/tests/test-cleanup.c b/src/core/platform/tests/test-cleanup.c index 2198e92124..ae5597a7c4 100644 --- a/src/core/platform/tests/test-cleanup.c +++ b/src/core/platform/tests/test-cleanup.c @@ -63,7 +63,7 @@ test_cleanup_internal(void) nm_platform_process_events(NM_PLATFORM_GET); } addrs = nmtstp_platform_ip6_address_get_all(NM_PLATFORM_GET, ifindex); - if (addrs->len == 1 && (a = &g_array_index(addrs, NMPlatformIP6Address, 0)) + if (addrs->len == 1 && (a = &nm_g_array_index(addrs, NMPlatformIP6Address, 0)) && IN6_IS_ADDR_LINKLOCAL(&a->address)) break; }); diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c index d97d272dc0..5e13ec13f3 100644 --- a/src/core/platform/tests/test-link.c +++ b/src/core/platform/tests/test-link.c @@ -2511,7 +2511,7 @@ test_create_many_links_do(guint n_devices) if (EX == 2) nmtstp_run_command_check("ip link delete %s", name); else - nmtstp_link_delete(NULL, EX, g_array_index(ifindexes, int, i), name, TRUE); + nmtstp_link_delete(NULL, EX, nm_g_array_index(ifindexes, int, i), name, TRUE); } _LOGI(">>> process events after deleting devices..."); diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index de510c76a4..872b894214 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -528,27 +528,29 @@ test_nm_utils_array_remove_at_indexes(void) _remove_at_indexes_init_random_idx(idx, i_len, i_idx_len); g_array_set_size(array, i_len); for (i = 0; i < i_len; i++) - g_array_index(array, gssize, i) = i; + nm_g_array_index(array, gssize, i) = i; - nm_utils_array_remove_at_indexes(array, &g_array_index(idx, guint, 0), i_idx_len); + nm_utils_array_remove_at_indexes(array, + nm_g_array_index_p(idx, guint, 0), + i_idx_len); g_hash_table_remove_all(unique); /* ensure that all the indexes are still unique */ for (i = 0; i < array->len; i++) - g_hash_table_add(unique, GUINT_TO_POINTER(g_array_index(array, gssize, i))); + g_hash_table_add(unique, GUINT_TO_POINTER(nm_g_array_index(array, gssize, i))); g_assert_cmpint(g_hash_table_size(unique), ==, array->len); for (i = 0; i < idx->len; i++) - g_hash_table_add(unique, GUINT_TO_POINTER(g_array_index(idx, guint, i))); + g_hash_table_add(unique, GUINT_TO_POINTER(nm_g_array_index(idx, guint, i))); g_assert_cmpint(g_hash_table_size(unique), ==, i_len); /* ensure proper sort order in array */ for (i = 0; i < array->len; i++) { - gssize i1 = g_array_index(array, gssize, i); + gssize i1 = nm_g_array_index(array, gssize, i); g_assert(i1 >= 0 && i1 < i_len); if (i > 0) { - gsize i0 = g_array_index(array, gssize, i - 1); + gsize i0 = nm_g_array_index(array, gssize, i - 1); g_assert_cmpint(i0, <, i1); } } diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 55687179be..1c5f3a313e 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -339,7 +339,7 @@ nm_setting_connection_get_permission(NMSettingConnection *setting, g_return_val_if_fail(idx < nm_g_array_len(priv->permissions), FALSE); - permission = &g_array_index(priv->permissions, Permission, idx); + permission = &nm_g_array_index(priv->permissions, Permission, idx); switch (permission->ptype) { case PERM_TYPE_USER: NM_SET_OUT(out_ptype, NM_SETTINGS_CONNECTION_PERMISSION_USER); @@ -384,7 +384,7 @@ nm_setting_connection_permissions_user_allowed(NMSettingConnection *setting, con } for (i = 0; i < priv->permissions->len; i++) { - const Permission *permission = &g_array_index(priv->permissions, Permission, i); + const Permission *permission = &nm_g_array_index(priv->permissions, Permission, i); if (permission->ptype == PERM_TYPE_USER && nm_streq(permission->item, uname)) return TRUE; @@ -440,7 +440,7 @@ nm_setting_connection_add_permission(NMSettingConnection *setting, } for (i = 0; i < priv->permissions->len; i++) { - const Permission *permission = &g_array_index(priv->permissions, Permission, i); + const Permission *permission = &nm_g_array_index(priv->permissions, Permission, i); if (permission->ptype == PERM_TYPE_USER && nm_streq(permission->item, pitem)) return TRUE; @@ -511,7 +511,7 @@ nm_setting_connection_remove_permission_by_value(NMSettingConnection *setting, priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting); if (priv->permissions) { for (i = 0; i < priv->permissions->len; i++) { - const Permission *permission = &g_array_index(priv->permissions, Permission, i); + const Permission *permission = &nm_g_array_index(priv->permissions, Permission, i); if (permission->ptype == PERM_TYPE_USER && nm_streq(permission->item, pitem)) { g_array_remove_index(priv->permissions, i); @@ -1490,7 +1490,7 @@ after_interface_name: guint i; for (i = 0; i < priv->permissions->len; i++) { - const Permission *permissions = &g_array_index(priv->permissions, Permission, i); + const Permission *permissions = &nm_g_array_index(priv->permissions, Permission, i); if (permissions->ptype != PERM_TYPE_USER) { g_set_error_literal(error, @@ -1709,7 +1709,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) strv = g_new(char *, l + 1u); for (i = 0; i < l; i++) - strv[i] = _permission_to_string(&g_array_index(priv->permissions, Permission, i)); + strv[i] = _permission_to_string(&nm_g_array_index(priv->permissions, Permission, i)); strv[i] = NULL; g_value_take_boxed(value, strv); diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index cafdcd2b4a..5f4fb8bbfd 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5649,14 +5649,14 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) for (i = 0; i < priv->dhcp_reject_servers->len; i++) { if (!nm_inet_parse_with_prefix_str( NM_SETTING_IP_CONFIG_GET_FAMILY(setting), - g_array_index(priv->dhcp_reject_servers, const char *, i), + nm_g_array_index(priv->dhcp_reject_servers, const char *, i), NULL, NULL)) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' is not a valid IP or subnet"), - g_array_index(priv->dhcp_reject_servers, const char *, i)); + nm_g_array_index(priv->dhcp_reject_servers, const char *, i)); g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 947ffe6ff2..3e08369f85 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -327,7 +327,7 @@ nm_setting_wired_get_mac_blacklist_item(NMSettingWired *setting, guint32 idx) priv = NM_SETTING_WIRED_GET_PRIVATE(setting); g_return_val_if_fail(idx <= priv->mac_address_blacklist->len, NULL); - return g_array_index(priv->mac_address_blacklist, const char *, idx); + return nm_g_array_index(priv->mac_address_blacklist, const char *, idx); } /** @@ -355,7 +355,7 @@ nm_setting_wired_add_mac_blacklist_item(NMSettingWired *setting, const char *mac priv = NM_SETTING_WIRED_GET_PRIVATE(setting); for (i = 0; i < priv->mac_address_blacklist->len; i++) { - candidate = g_array_index(priv->mac_address_blacklist, char *, i); + candidate = nm_g_array_index(priv->mac_address_blacklist, char *, i); if (nm_utils_hwaddr_matches(mac, -1, candidate, -1)) return FALSE; } @@ -409,7 +409,7 @@ nm_setting_wired_remove_mac_blacklist_item_by_value(NMSettingWired *setting, con priv = NM_SETTING_WIRED_GET_PRIVATE(setting); for (i = 0; i < priv->mac_address_blacklist->len; i++) { - candidate = g_array_index(priv->mac_address_blacklist, char *, i); + candidate = nm_g_array_index(priv->mac_address_blacklist, char *, i); if (!nm_utils_hwaddr_matches(mac, -1, candidate, -1)) { g_array_remove_index(priv->mac_address_blacklist, i); _notify(setting, PROP_MAC_ADDRESS_BLACKLIST); @@ -810,7 +810,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } for (i = 0; i < priv->mac_address_blacklist->len; i++) { - const char *mac = g_array_index(priv->mac_address_blacklist, const char *, i); + const char *mac = nm_g_array_index(priv->mac_address_blacklist, const char *, i); if (!nm_utils_hwaddr_valid(mac, ETH_ALEN)) { g_set_error(error, diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 30de4cef44..6d27ba8400 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -508,7 +508,7 @@ nm_setting_wireless_get_mac_blacklist_item(NMSettingWireless *setting, guint32 i priv = NM_SETTING_WIRELESS_GET_PRIVATE(setting); g_return_val_if_fail(idx <= priv->mac_address_blacklist->len, NULL); - return g_array_index(priv->mac_address_blacklist, const char *, idx); + return nm_g_array_index(priv->mac_address_blacklist, const char *, idx); } /** @@ -536,7 +536,7 @@ nm_setting_wireless_add_mac_blacklist_item(NMSettingWireless *setting, const cha priv = NM_SETTING_WIRELESS_GET_PRIVATE(setting); for (i = 0; i < priv->mac_address_blacklist->len; i++) { - candidate = g_array_index(priv->mac_address_blacklist, char *, i); + candidate = nm_g_array_index(priv->mac_address_blacklist, char *, i); if (nm_utils_hwaddr_matches(mac, -1, candidate, -1)) return FALSE; } @@ -590,7 +590,7 @@ nm_setting_wireless_remove_mac_blacklist_item_by_value(NMSettingWireless *settin priv = NM_SETTING_WIRELESS_GET_PRIVATE(setting); for (i = 0; i < priv->mac_address_blacklist->len; i++) { - candidate = g_array_index(priv->mac_address_blacklist, char *, i); + candidate = nm_g_array_index(priv->mac_address_blacklist, char *, i); if (!nm_utils_hwaddr_matches(mac, -1, candidate, -1)) { g_array_remove_index(priv->mac_address_blacklist, i); _notify(setting, PROP_MAC_ADDRESS_BLACKLIST); @@ -988,7 +988,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } for (i = 0; i < priv->mac_address_blacklist->len; i++) { - const char *mac = g_array_index(priv->mac_address_blacklist, const char *, i); + const char *mac = nm_g_array_index(priv->mac_address_blacklist, const char *, i); if (!nm_utils_hwaddr_valid(mac, ETH_ALEN)) { g_set_error(error, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 8e975b64bd..2f0b338eee 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -317,7 +317,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class, override_len = properties_override->len; for (i = 0; i < override_len; i++) { - NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i); + NMSettInfoProperty *p = &nm_g_array_index(properties_override, NMSettInfoProperty, i); nm_assert((!!p->name) != (!!p->param_spec)); @@ -332,7 +332,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class, #if NM_MORE_ASSERTS > 10 /* assert that properties_override is constructed consistently. */ for (i = 0; i < override_len; i++) { - const NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i); + const NMSettInfoProperty *p = &nm_g_array_index(properties_override, NMSettInfoProperty, i); gboolean found = FALSE; guint k; @@ -367,7 +367,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class, } for (i = 0; i < properties_override->len; i++) { - NMSettInfoProperty *p = &g_array_index(properties_override, NMSettInfoProperty, i); + NMSettInfoProperty *p = &nm_g_array_index(properties_override, NMSettInfoProperty, i); GType vtype; if (p->property_type) diff --git a/src/libnm-core-impl/nm-vpn-plugin-info.c b/src/libnm-core-impl/nm-vpn-plugin-info.c index 473063fbca..a6096563ba 100644 --- a/src/libnm-core-impl/nm-vpn-plugin-info.c +++ b/src/libnm-core-impl/nm-vpn-plugin-info.c @@ -296,7 +296,7 @@ _nm_vpn_plugin_info_list_load_dir(const char *dirname, g_array_sort(array, (GCompareFunc) _sort_files); for (i = 0; i < array->len; i++) - res = g_slist_prepend(res, g_array_index(array, LoadDirInfo, i).plugin_info); + res = g_slist_prepend(res, nm_g_array_index(array, LoadDirInfo, i).plugin_info); g_array_unref(array); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 6306437118..429db52294 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4303,7 +4303,7 @@ _PROP_IDX_OWNER(GHashTable *h_property_types, const NMSettInfoPropertType *prope g_assert(arr); g_assert(arr->len > 0); - idx = g_array_index(arr, guint, 0); + idx = nm_g_array_index(arr, guint, 0); meta_type = (idx & 0xFFu); prop_idx = idx >> 8; diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index caf275f454..8bb5e21af6 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -2858,7 +2858,7 @@ nm_strvarray_add(GArray *array, const char *str) static inline const char * nm_strvarray_get_idx(GArray *array, guint idx) { - return *nm_g_array_index_p(array, const char *, idx); + return nm_g_array_index(array, const char *, idx); } static inline const char *const * diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index fd2ddf86fb..144b3a85b7 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -661,7 +661,7 @@ __nmtst_init(int *argc, /* Delay messages until we setup logging. */ for (i = 0; i < debug_messages->len; i++) - __NMTST_LOG(g_message, "%s", g_array_index(debug_messages, const char *, i)); + __NMTST_LOG(g_message, "%s", nm_g_array_index(debug_messages, const char *, i)); g_strfreev((char **) g_array_free(debug_messages, FALSE)); g_free(c_log_level); diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 03725b2558..6d972584dd 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -6259,11 +6259,11 @@ static NM_UTILS_LOOKUP_STR_DEFINE( NM_UTILS_LOOKUP_ITEM_IGNORE(DELAYED_ACTION_TYPE_REFRESH_ALL_RTNL_ROUTING_RULES_ALL), NM_UTILS_LOOKUP_ITEM_IGNORE(__DELAYED_ACTION_TYPE_MAX), ); -#define delayed_action_get_list_wait_for_resonse(priv, netlink_protocol, idx) \ - (&g_array_index((priv)->delayed_action.list_wait_for_response_x[nmp_netlink_protocol_check( \ - (netlink_protocol))], \ - DelayedActionWaitForNlResponseData, \ - (idx))) +#define delayed_action_get_list_wait_for_resonse(priv, netlink_protocol, idx) \ + (&nm_g_array_index((priv)->delayed_action.list_wait_for_response_x[nmp_netlink_protocol_check( \ + (netlink_protocol))], \ + DelayedActionWaitForNlResponseData, \ + (idx))) static const char * delayed_action_to_string_full(DelayedActionType action_type, diff --git a/src/libnm-platform/nmp-global-tracker.c b/src/libnm-platform/nmp-global-tracker.c index ea4da28482..b1231ace41 100644 --- a/src/libnm-platform/nmp-global-tracker.c +++ b/src/libnm-platform/nmp-global-tracker.c @@ -784,7 +784,7 @@ nmp_global_tracker_sync_mptcp_addrs(NMPGlobalTracker *self, gboolean reapply) /* Now, drop all duplicates addresses. Only keep the first one. */ for (i = 0, j = 0; i < entries->len; i++) { - const MptcpSyncData *d = nm_g_array_index_p(entries, MptcpSyncData, i); + const MptcpSyncData *d = &nm_g_array_index(entries, MptcpSyncData, i); const NMPlatformMptcpAddr *mptcp_addr = NMP_OBJECT_CAST_MPTCP_ADDR(d->obj_data->obj); obj_data = g_hash_table_lookup(entries_hash_by_addr, (gpointer) mptcp_addr); @@ -810,7 +810,7 @@ nmp_global_tracker_sync_mptcp_addrs(NMPGlobalTracker *self, gboolean reapply) nm_assert_not_reached(); if (i != j) - *(nm_g_array_index_p(entries, MptcpSyncData, j)) = *d; + (nm_g_array_index(entries, MptcpSyncData, j)) = *d; j++; if (j >= MPTCP_PM_ADDR_MAX) { @@ -915,7 +915,7 @@ keep_and_next: if (entries) { for (i = 0; i < entries->len; i++) { - const MptcpSyncData *d = nm_g_array_index_p(entries, MptcpSyncData, i); + const MptcpSyncData *d = &nm_g_array_index(entries, MptcpSyncData, i); const NMPlatformMptcpAddr *mptcp_addr = NMP_OBJECT_CAST_MPTCP_ADDR(d->obj_data->obj); const NMPObject *kobj; diff --git a/src/libnm-platform/nmp-netns.c b/src/libnm-platform/nmp-netns.c index b3e2e043c0..864e30e94f 100644 --- a/src/libnm-platform/nmp-netns.c +++ b/src/libnm-platform/nmp-netns.c @@ -194,7 +194,7 @@ _stack_current_netns(GArray *netns_stack, int ns_types) for (j = netns_stack->len; ns_types && j >= 1;) { NetnsInfo *info; - info = &g_array_index(netns_stack, NetnsInfo, --j); + info = &nm_g_array_index(netns_stack, NetnsInfo, --j); if (NM_FLAGS_ALL(info->ns_types, ns_types)) return info->netns; @@ -218,7 +218,7 @@ _stack_current_ns_types(GArray *netns_stack, NMPNetns *netns, int ns_types) for (j = netns_stack->len; ns_types && j >= 1;) { NetnsInfo *info; - info = &g_array_index(netns_stack, NetnsInfo, --j); + info = &nm_g_array_index(netns_stack, NetnsInfo, --j); if (info->netns != netns) { ns_types = NM_FLAGS_UNSET(ns_types, info->ns_types); continue; @@ -240,7 +240,7 @@ static NetnsInfo * _stack_peek(GArray *netns_stack) { if (netns_stack->len > 0) - return &g_array_index(netns_stack, NetnsInfo, (netns_stack->len - 1)); + return &nm_g_array_last(netns_stack, NetnsInfo); return NULL; } @@ -248,7 +248,7 @@ static NetnsInfo * _stack_bottom(GArray *netns_stack) { if (netns_stack->len > 0) - return &g_array_index(netns_stack, NetnsInfo, 0); + return &nm_g_array_first(netns_stack, NetnsInfo); return NULL; } @@ -278,7 +278,7 @@ _stack_pop(GArray *netns_stack) nm_assert(netns_stack); nm_assert(netns_stack->len > 1); - info = &g_array_index(netns_stack, NetnsInfo, (netns_stack->len - 1)); + info = &nm_g_array_last(netns_stack, NetnsInfo); nm_assert(NMP_IS_NETNS(info->netns)); nm_assert(info->count == 1); diff --git a/src/libnmc-setting/nm-meta-setting-access.c b/src/libnmc-setting/nm-meta-setting-access.c index 7f679ae5fa..1485704840 100644 --- a/src/libnmc-setting/nm-meta-setting-access.c +++ b/src/libnmc-setting/nm-meta-setting-access.c @@ -416,7 +416,7 @@ _output_selection_pack(const NMMetaAbstractInfo *const *fields_array, GArray *ar if (str) memcpy(pdata, str->str, str->len); for (i = 0; i < len; i++) { - const OutputSelectionItem *a = &g_array_index(array, OutputSelectionItem, i); + const OutputSelectionItem *a = &nm_g_array_index(array, OutputSelectionItem, i); NMMetaSelectionItem *p = (NMMetaSelectionItem *) &result->items[i]; p->info = fields_array[a->idx]; diff --git a/src/nm-initrd-generator/nm-initrd-generator.c b/src/nm-initrd-generator/nm-initrd-generator.c index 09f8baf21a..cff678f84e 100644 --- a/src/nm-initrd-generator/nm-initrd-generator.c +++ b/src/nm-initrd-generator/nm-initrd-generator.c @@ -241,7 +241,7 @@ main(int argc, char *argv[]) g_print("\n*** Hostname '%s' ***\n", hostname); for (i = 0; i < confs->len; i++) { - NMUtilsNamedValue *v = &g_array_index(confs, NMUtilsNamedValue, i); + NMUtilsNamedValue *v = &nm_g_array_index(confs, NMUtilsNamedValue, i); gs_free char *name = g_path_get_basename(v->name); g_print("\n*** Configuration '%s' ***\n\n%s\n", name, v->value_str); @@ -277,7 +277,7 @@ main(int argc, char *argv[]) } for (i = 0; i < confs->len; i++) { - NMUtilsNamedValue *v = &g_array_index(confs, NMUtilsNamedValue, i); + NMUtilsNamedValue *v = &nm_g_array_index(confs, NMUtilsNamedValue, i); if (!g_file_set_contents(v->name, v->value_str, strlen(v->value_str), &error)) { _LOGW(LOGD_CORE, "%s: %s", v->name, error->message); diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 8c6ebd9897..37fa6c4baf 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -1610,7 +1610,7 @@ nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) /* Loop through the required settings and print them. */ for (i = 0; i < print_settings_array->len; i++) { NMSetting *setting; - int section_idx = g_array_index(print_settings_array, int, i); + int section_idx = nm_g_array_index(print_settings_array, int, i); const char *prop_name = (const char *) g_ptr_array_index(prop_array, i); if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) @@ -1716,7 +1716,7 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) /* Loop through the groups and print them. */ for (i = 0; i < print_groups->len; i++) { - int group_idx = g_array_index(print_groups, int, i); + int group_idx = nm_g_array_index(print_groups, int, i); char *group_fld = (char *) g_ptr_array_index(group_fields, i); if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) @@ -1983,7 +1983,7 @@ con_show_get_items_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) nmc_print_output_to_accessor_get_type(sort_info->nmc->nmc_config.print_output); if (sort_info->order) { - order_arr = &g_array_index(sort_info->order, NmcSortOrder, 0); + order_arr = nm_g_array_index_p(sort_info->order, NmcSortOrder, 0); order_len = sort_info->order->len; } else { static const NmcSortOrder def[] = {NMC_SORT_ACTIVE, NMC_SORT_NAME, NMC_SORT_PATH}; @@ -2206,7 +2206,7 @@ parse_preferred_connection_order(const char *order, GError **error) /* Check for duplicates and ignore them. */ unique = TRUE; for (i = 0; i < order_arr->len; i++) { - if (abs(g_array_index(order_arr, NmcSortOrder, i)) - abs(val) == 0) { + if (abs(nm_g_array_index(order_arr, NmcSortOrder, i)) - abs(val) == 0) { unique = FALSE; break; } diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index 5b8d0ce01a..dbba6bb61c 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -1642,7 +1642,7 @@ show_device_info(NMDevice *device, NmCli *nmc) /* Loop through the required sections and print them. */ for (k = 0; k < sections_array->len; k++) { - int section_idx = g_array_index(sections_array, int, k); + int section_idx = nm_g_array_index(sections_array, int, k); char *section_fld = (char *) g_ptr_array_index(fields_in_section, k); if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) diff --git a/src/nmcli/utils.c b/src/nmcli/utils.c index 209a5b6938..2342449e38 100644 --- a/src/nmcli/utils.c +++ b/src/nmcli/utils.c @@ -691,7 +691,7 @@ _output_selection_append(GArray *cols, if (parent_idx != PRINT_DATA_COL_PARENT_NIL) { const NMMetaSelectionItem *si; - si = g_array_index(cols, PrintDataCol, parent_idx).selection_item; + si = nm_g_array_index(cols, PrintDataCol, parent_idx).selection_item; allowed_fields = nm_meta_abstract_info_get_nested_names_str(si->info, si->self_selection); } @@ -741,7 +741,7 @@ _output_selection_append(GArray *cols, if (!NM_IN_SET(selection_item->info->meta_type, &nm_meta_type_setting_info_editor, &nmc_meta_type_generic_info)) - g_array_index(cols, PrintDataCol, col_idx).is_leaf = FALSE; + nm_g_array_index(cols, PrintDataCol, col_idx).is_leaf = FALSE; } return TRUE; @@ -756,13 +756,13 @@ _output_selection_complete(GArray *cols) nm_assert(g_array_get_element_size(cols) == sizeof(PrintDataCol)); for (i = 0; i < cols->len; i++) { - PrintDataCol *col = &g_array_index(cols, PrintDataCol, i); + PrintDataCol *col = &nm_g_array_index(cols, PrintDataCol, i); if (col->_parent_idx == PRINT_DATA_COL_PARENT_NIL) col->parent_col = NULL; else { nm_assert(col->_parent_idx < i); - col->parent_col = &g_array_index(cols, PrintDataCol, col->_parent_idx); + col->parent_col = &nm_g_array_index(cols, PrintDataCol, col->_parent_idx); } } } @@ -1026,7 +1026,7 @@ _print_fill(const NmcConfig *nmc_config, col_idx = header_row->len; g_array_set_size(header_row, col_idx + 1); - header_cell = &g_array_index(header_row, PrintDataHeaderCell, col_idx); + header_cell = &nm_g_array_index(header_row, PrintDataHeaderCell, col_idx); header_cell->col_idx = col_idx; header_cell->col = col; @@ -1060,8 +1060,9 @@ _print_fill(const NmcConfig *nmc_config, text_get_flags |= NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS; for (i_row = 0; i_row < targets_len; i_row++) { - gpointer target = targets[i_row]; - PrintDataCell *cells_line = &g_array_index(cells, PrintDataCell, i_row * header_row->len); + gpointer target = targets[i_row]; + PrintDataCell *cells_line = + &nm_g_array_index(cells, PrintDataCell, i_row * header_row->len); for (i_col = 0; i_col < header_row->len; i_col++) { char *to_free = NULL; @@ -1072,7 +1073,7 @@ _print_fill(const NmcConfig *nmc_config, gconstpointer value; gboolean is_default; - header_cell = &g_array_index(header_row, PrintDataHeaderCell, i_col); + header_cell = &nm_g_array_index(header_row, PrintDataHeaderCell, i_col); info = header_cell->col->selection_item->info; cell->row_idx = i_row; @@ -1147,13 +1148,14 @@ _print_fill(const NmcConfig *nmc_config, } for (i_col = 0; i_col < header_row->len; i_col++) { - PrintDataHeaderCell *header_cell = &g_array_index(header_row, PrintDataHeaderCell, i_col); + PrintDataHeaderCell *header_cell = + &nm_g_array_index(header_row, PrintDataHeaderCell, i_col); header_cell->width = nmc_string_screen_width(header_cell->title, NULL); for (i_row = 0; i_row < targets_len; i_row++) { const PrintDataCell *cells_line = - &g_array_index(cells, PrintDataCell, i_row * header_row->len); + &nm_g_array_index(cells, PrintDataCell, i_row * header_row->len); const PrintDataCell *cell = &cells_line[i_col]; const char *const *i_strv; @@ -1408,8 +1410,8 @@ nmc_print(const NmcConfig *nmc_config, header_name_no_l10n, header_row->len, cells->len / header_row->len, - &g_array_index(header_row, PrintDataHeaderCell, 0), - &g_array_index(cells, PrintDataCell, 0)); + nm_g_array_index_p(header_row, PrintDataHeaderCell, 0), + nm_g_array_index_p(cells, PrintDataCell, 0)); return TRUE; } @@ -1624,7 +1626,7 @@ print_required_fields(const NmcConfig *nmc_config, if (nmc_config->multiline_output) { for (i = 0; i < indices->len; i++) { - int idx = g_array_index(indices, int, i); + int idx = nm_g_array_index(indices, int, i); gboolean is_array = field_values[idx].value_is_array; /* section prefix can't be an array */ @@ -1705,7 +1707,7 @@ print_required_fields(const NmcConfig *nmc_config, int idx; const char *value; - idx = g_array_index(indices, int, i); + idx = nm_g_array_index(indices, int, i); value = get_value_to_print(nmc_config, (NmcOutputField *) field_values + idx, From e6b9f6ecd0b44db0c5088de55a609c6956f14c42 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Sep 2022 11:51:26 +0200 Subject: [PATCH 4/4] contrib: discourage g_array_index() in "checkpatch.pl" --- contrib/scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/scripts/checkpatch.pl b/contrib/scripts/checkpatch.pl index fa5a865120..e82000302a 100755 --- a/contrib/scripts/checkpatch.pl +++ b/contrib/scripts/checkpatch.pl @@ -203,6 +203,7 @@ complain ("Prefer nm_pint_hash()/nm_pint64_hash()/nm_pdouble_hash() over g_int_h complain ("Prefer nm_pint_equal()/nm_pint64_equal()/nm_pdouble_equal() over g_int_equal()/g_int64_equal()/g_double_equal(). Those names mirror our nm_p*_hash() functions") if $line =~ /\b(g_int_equal|g_int64_equal|g_double_equal)\b/; complain ("Avoid g_clear_pointer() and use nm_clear_pointer() (or nm_clear_g_free(), g_clear_object(), etc.)") if $line =~ /\b(g_clear_pointer)\b/; complain ("Define setting properties with _nm_setting_property_define_direct_*() API") if $line =~ /g_param_spec_/ and $filename =~ /\/libnm-core-impl\/nm-setting/; +complain ("Use nm_g_array_{index,first,last,index_p}() instead of g_array_index(), as it nm_assert()s for valid element size and out-of-bound access") if $line =~ /\bg_array_index\b/; complain ("Use spaces instead of tabs") if $line =~ /\t/; # Further on we process stuff without comments.