From 4e3955e6ddf02d5ea32012bd563aa02fece5c0ef Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 1 May 2019 11:53:13 +0200 Subject: [PATCH] libnm: mark NMVariantAttributeSpec pointers as const This actually allows the compiler/linker to mark the memory as read-only and any modification will cause a segmentation fault. I would also think that it allows the compiler to put the structure directly beside the outer constant array (in which this pointer is embedded). That is good locality-wise. --- libnm-core/nm-setting-ip-config.c | 2 +- libnm-core/nm-setting-sriov.c | 2 +- libnm-core/nm-utils.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 1003994f10..6155719de1 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -1213,7 +1213,7 @@ nm_ip_route_set_attribute (NMIPRoute *route, const char *name, GVariant *value) } #define ATTR_SPEC_PTR(name, type, v4, v6, str_type) \ - &(NMVariantAttributeSpec) { name, type, v4, v6, FALSE, FALSE, str_type } + &((const NMVariantAttributeSpec) { name, type, v4, v6, FALSE, FALSE, str_type }) static const NMVariantAttributeSpec * const ip_route_attribute_spec[] = { ATTR_SPEC_PTR (NM_IP_ROUTE_ATTRIBUTE_TABLE, G_VARIANT_TYPE_UINT32, TRUE, TRUE, 0 ), diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index a5d672382c..3547baf20f 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -366,7 +366,7 @@ nm_sriov_vf_get_attribute (const NMSriovVF *vf, const char *name) } #define SRIOV_ATTR_SPEC_PTR(name, type, str_type) \ - &(NMVariantAttributeSpec) { name, type, FALSE, FALSE, FALSE, FALSE, str_type } + &((const NMVariantAttributeSpec) { name, type, FALSE, FALSE, FALSE, FALSE, str_type }) const NMVariantAttributeSpec * const _nm_sriov_vf_attribute_spec[] = { SRIOV_ATTR_SPEC_PTR (NM_SRIOV_VF_ATTRIBUTE_MAC, G_VARIANT_TYPE_STRING, 'm'), diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index d25aa45245..215823a197 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2318,7 +2318,7 @@ fail: } #define TC_ATTR_SPEC_PTR(name, type, no_value, consumes_rest, str_type) \ - &(NMVariantAttributeSpec) { name, type, FALSE, FALSE, no_value, consumes_rest, str_type } + &((const NMVariantAttributeSpec) { name, type, FALSE, FALSE, no_value, consumes_rest, str_type }) static const NMVariantAttributeSpec * const tc_object_attribute_spec[] = { TC_ATTR_SPEC_PTR ("root", G_VARIANT_TYPE_BOOLEAN, TRUE, FALSE, 0 ),