diff --git a/src/nm-cloud-setup/nmcs-provider.c b/src/nm-cloud-setup/nmcs-provider.c index a519ef9b5e..fd9a61b813 100644 --- a/src/nm-cloud-setup/nmcs-provider.c +++ b/src/nm-cloud-setup/nmcs-provider.c @@ -192,6 +192,17 @@ nmcs_provider_get_config_iface_data_create(NMCSProviderGetConfigTaskData *get_co .was_requested = was_requested, }; + /* "priv" is a union, and according to C, it might not be properly initialized + * that all union members are set to false/0/NULL/0.0. We need to know which + * union field we are going to use, and that depends on the type of "self". + * Also, knowing the type would allow us to initialize to something other than + * false/0/NULL/0.0. */ + if (G_OBJECT_TYPE(get_config_data->self) == nmcs_provider_aliyun_get_type()) { + iface_data->priv.aliyun = (typeof(iface_data->priv.aliyun)){ + .has_primary_ip_address = FALSE, + }; + } + /* the has does not own the key (iface_datta->hwaddr), the lifetime of the * key is associated with the iface_data instance. */ g_hash_table_replace(get_config_data->result_dict, (char *) iface_data->hwaddr, iface_data); diff --git a/src/nm-cloud-setup/nmcs-provider.h b/src/nm-cloud-setup/nmcs-provider.h index d1ab0a33c2..502f1d0323 100644 --- a/src/nm-cloud-setup/nmcs-provider.h +++ b/src/nm-cloud-setup/nmcs-provider.h @@ -45,7 +45,7 @@ typedef struct { * the implementations. However, it's convenient to track implementation specific data * here, thus we violate such separation. In practice, all subclasses are known * at compile time, and it will be simpler this way. */ - struct { + union { struct { in_addr_t primary_ip_address; bool has_primary_ip_address : 1; @@ -191,4 +191,11 @@ void nmcs_provider_get_config(NMCSProvider *provider, NMCSProviderGetConfigResult * nmcs_provider_get_config_finish(NMCSProvider *provider, GAsyncResult *result, GError **error); +/*****************************************************************************/ + +/* Forward declare the implemented gtype getters so we can use it at a few places without requiring + * to include the full header. The other parts of those headers should not be used aside where they + * are necessary. */ +GType nmcs_provider_aliyun_get_type(void); + #endif /* __NMCS_PROVIDER_H__ */