libnm: avoid "-Wmaybe-uninitialized" warning in nm_setting_ethtool_get_optnames()

With LTO build on s390x (Fedora 33) we get a compiler warning:

    libnm-core/nm-setting-ethtool.c: In function 'nm_setting_ethtool_get_optnames':
    libnm-core/nm-setting-ethtool.c:263:60: error: 'len' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      263 |     return len > 0 ? nm_memdup(names, sizeof(names[0]) * (((gsize) len) + 1u)) : NULL;
          |                                                            ^
    libnm-core/nm-setting-ethtool.c:257:24: note: 'len' was declared here
      257 |     guint              len;
          |                        ^
    libnm-core/nm-setting-ethtool.c: In function 'nm_setting_ethtool_get_optnames':
    libnm-core/nm-setting-ethtool.c:263:60: error: 'len' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      263 |     return len > 0 ? nm_memdup(names, sizeof(names[0]) * (((gsize) len) + 1u)) : NULL;
          |                                                            ^
    libnm-core/nm-setting-ethtool.c:257:24: note: 'len' was declared here
      257 |     guint              len;
          |                        ^
This commit is contained in:
Thomas Haller 2021-01-12 16:32:58 +01:00
parent d26fa1cd52
commit 63a33b3542
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -254,7 +254,7 @@ const char **
nm_setting_ethtool_get_optnames(NMSettingEthtool *setting, guint *out_length)
{
const char *const *names;
guint len;
guint len = 0;
g_return_val_if_fail(NM_IS_SETTING_ETHTOOL(setting), NULL);