platform: avoid "-Wmaybe-uninitialized" warning in ip_route_add()

When building without "more-asserts" and LTO enabled, we can get
a warning about uninitalized "obj" variable:

    src/platform/nm-linux-platform.c: In function 'ip_route_add':
    src/platform/nm-platform.c:4761:24: warning: 'MEM[(struct NMPlatformIPRoute *)&obj + 24B].rt_source' may be used uninitialized in this function [-Wmaybe-uninitialized]
     4761 |     route->rt_source = nmp_utils_ip_config_source_round_trip_rtprot(route->rt_source);
          |                        ^
    src/platform/nm-platform.h:2139:25: warning: 'BIT_FIELD_REF <MEM[(const struct NMPlatformIPRoute *)&obj + 24B], 8, 72>' may be used uninitialized in this function [-Wmaybe-uninitialized]
     2139 |     return r->table_any ? 254u /* RT_TABLE_MAIN */
          |

That is due to the "default" switch case which was unhandled
when building without more-asserts". Avoid that by reworking the
code.
This commit is contained in:
Thomas Haller
2021-01-08 13:10:12 +01:00
parent 89f808efcb
commit fc6475bbf7

View File

@@ -8634,16 +8634,9 @@ ip_route_add(NMPlatform * platform,
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
NMPObject obj;
switch (addr_family) {
case AF_INET:
nmp_object_stackinit(&obj, NMP_OBJECT_TYPE_IP4_ROUTE, (const NMPlatformObject *) route);
break;
case AF_INET6:
nmp_object_stackinit(&obj, NMP_OBJECT_TYPE_IP6_ROUTE, (const NMPlatformObject *) route);
break;
default:
nm_assert_not_reached();
}
nmp_object_stackinit(&obj,
NMP_OBJECT_TYPE_IP_ROUTE(NM_IS_IPv4(addr_family)),
(const NMPlatformObject *) route);
nm_platform_ip_route_normalize(addr_family, NMP_OBJECT_CAST_IP_ROUTE(&obj));