all: avoid wrong compiler warning about uninitalized variables with LTO

Seems with LTO the compiler can sometimes think that thes variables are
uninitialized. Usually those code paths are only after an assertion was
hit (g_return*()), but we still need to workaround the warning.
This commit is contained in:
Thomas Haller 2020-08-12 14:01:21 +02:00
parent 0bd8160029
commit 70971d1141
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
11 changed files with 36 additions and 13 deletions

View file

@ -458,8 +458,8 @@ _poll_get_probe_finish_fcn (GObject *source,
_nm_unused gs_unref_object GTask *task = poll_get_data->task; /* balance ref from _poll_get_probe_start_fcn() */
gboolean success;
gs_free_error GError *local_error = NULL;
long response_code;
gs_unref_bytes GBytes *response_data = NULL;
long response_code = -1;
success = nm_http_client_get_finish (g_task_get_source_object (poll_get_data->task),
result,

View file

@ -144,12 +144,12 @@ nm_keyfile_plugin_kf_get_integer_list_uint (GKeyFile *key_file,
gs_free guint *int_values = NULL;
gsize i, num_ints;
NM_SET_OUT (out_length, 0);
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
NM_SET_OUT (out_length, 0);
values = nm_keyfile_plugin_kf_get_string_list (key_file, group_name, key, &num_ints, &key_file_error);
if (key_file_error)

View file

@ -2294,9 +2294,9 @@ wired_s390_options_writer_full (KeyfileWriterInfo *info,
n = nm_setting_wired_get_num_s390_options (s_wired);
for (i = 0; i < n; i++) {
gs_free char *key_to_free = NULL;
const char *opt_key;
const char *opt_val;
gs_free char *key_to_free = NULL;
nm_setting_wired_get_s390_option (s_wired, i, &opt_key, &opt_val);
nm_keyfile_plugin_kf_set_string (info->keyfile,

View file

@ -269,6 +269,13 @@ nm_bridge_vlan_get_vid_range (const NMBridgeVlan *vlan,
guint16 *vid_start,
guint16 *vid_end)
{
/* with LTO and optimization, the compiler complains that the
* output variables are not initialized. In practice, the function
* only sets the output on success. But make the compiler happy.
*/
NM_SET_OUT (vid_start, 0);
NM_SET_OUT (vid_end, 0);
g_return_val_if_fail (NM_IS_BRIDGE_VLAN (vlan, TRUE), 0);
NM_SET_OUT (vid_start, vlan->vid_start);

View file

@ -490,6 +490,13 @@ nm_setting_wired_get_s390_option (NMSettingWired *setting,
{
NMSettingWiredPrivate *priv;
/* with LTO and optimization, the compiler complains that the
* output variables are not initialized. In practice, the function
* only sets the output on success. But make the compiler happy.
*/
NM_SET_OUT (out_key, NULL);
NM_SET_OUT (out_value, NULL);
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
priv = NM_SETTING_WIRED_GET_PRIVATE (setting);

View file

@ -592,13 +592,16 @@ nm_wireguard_peer_get_allowed_ip (const NMWireGuardPeer *self,
{
const char *s;
/* With LTO, the compiler might warn about the g_return_val_if_fail()
* code path not initializing the output argument. Workaround that by
* always setting the out argument. */
NM_SET_OUT (out_is_valid, FALSE);
g_return_val_if_fail (NM_IS_WIREGUARD_PEER (self, TRUE), NULL);
if ( !self->allowed_ips
|| idx >= self->allowed_ips->len) {
NM_SET_OUT (out_is_valid, FALSE);
|| idx >= self->allowed_ips->len)
return NULL;
}
s = self->allowed_ips->pdata[idx];
NM_SET_OUT (out_is_valid, s[0] != ALLOWED_IP_INVALID_X);

View file

@ -4209,7 +4209,10 @@ nm_utils_hexstr2bin_alloc (const char *hexstr,
guint8 *buffer;
gsize buffer_len, len;
g_return_val_if_fail (hexstr, NULL);
if (G_UNLIKELY (!hexstr)) {
NM_SET_OUT (out_len, 0);
g_return_val_if_fail (hexstr, NULL);
}
nm_assert (required_len > 0 || out_len);

View file

@ -107,7 +107,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
guint32 rebinding;
gs_free nm_sd_dhcp_option *private_options = NULL;
g_return_val_if_fail (lease != NULL, NULL);
nm_assert (lease != NULL);
if (sd_dhcp_lease_get_address (lease, &a_address) < 0) {
nm_utils_error_set_literal (error, NM_UTILS_ERROR_UNKNOWN, "could not get address from lease");
@ -481,9 +481,9 @@ bound4_handle (NMDhcpSystemd *self, gboolean extended)
{
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
sd_dhcp_lease *lease;
gs_unref_object NMIP4Config *ip4_config = NULL;
gs_unref_hashtable GHashTable *options = NULL;
sd_dhcp_lease *lease = NULL;
GError *error = NULL;
if ( sd_dhcp_client_get_lease (priv->client4, &lease) < 0
@ -744,7 +744,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
nm_auto_free_gstring GString *str = NULL;
int num, i;
g_return_val_if_fail (lease, NULL);
nm_assert (lease);
ip6_config = nm_ip6_config_new (multi_idx, ifindex);
@ -830,7 +830,7 @@ bound6_handle (NMDhcpSystemd *self)
gs_unref_hashtable GHashTable *options = NULL;
gs_free_error GError *error = NULL;
NMPlatformIP6Address prefix = { 0 };
sd_dhcp6_lease *lease;
sd_dhcp6_lease *lease = NULL;
if ( sd_dhcp6_client_get_lease (priv->client6, &lease) < 0
|| !lease) {

View file

@ -1361,6 +1361,8 @@ nm_config_data_get_device_config (const NMConfigData *self,
const MatchSectionInfo *connection_info;
char *value = NULL;
NM_SET_OUT (has_match, FALSE);
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (property && *property, NULL);

View file

@ -375,7 +375,7 @@ nm_ip4_config_lookup_routes (const NMIP4Config *self)
void
nm_ip_config_iter_ip4_route_init (NMDedupMultiIter *ipconf_iter, const NMIP4Config *self)
{
g_return_if_fail (NM_IS_IP4_CONFIG (self));
nm_assert (NM_IS_IP4_CONFIG (self));
nm_dedup_multi_iter_init (ipconf_iter, nm_ip4_config_lookup_routes (self));
}

View file

@ -171,6 +171,7 @@ nms_keyfile_reader_from_file (const char *full_filename,
NM_SET_OUT (out_is_nm_generated, NM_TERNARY_DEFAULT);
NM_SET_OUT (out_is_volatile, NM_TERNARY_DEFAULT);
NM_SET_OUT (out_is_external, NM_TERNARY_DEFAULT);
NM_SET_OUT (out_shadowed_owned, NM_TERNARY_DEFAULT);
if (!nms_keyfile_utils_check_file_permissions (NMS_KEYFILE_FILETYPE_KEYFILE,
full_filename,