diff --git a/src/generate.c b/src/generate.c index 658553752..aa5232437 100644 --- a/src/generate.c +++ b/src/generate.c @@ -340,7 +340,7 @@ int main(int argc, char** argv) start_unit_jit("systemd-networkd.service"); } g_autofree char* glob_run = g_build_path(G_DIR_SEPARATOR_S, - rootdir ?: G_DIR_SEPARATOR_S, + rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, "run/systemd/system/netplan-*.service", NULL); if (!glob(glob_run, 0, NULL, &gl)) { diff --git a/src/netplan.c b/src/netplan.c index 4c846d34e..6cf739708 100644 --- a/src/netplan.c +++ b/src/netplan.c @@ -209,7 +209,7 @@ STATIC gboolean write_vxlan(yaml_event_t* event, yaml_emitter_t* emitter, const NetplanNetDefinition* def) { if (def->type == NETPLAN_DEF_TYPE_TUNNEL && def->tunnel.mode == NETPLAN_TUNNEL_MODE_VXLAN) { - g_assert(def->vxlan); + g_assert(def->vxlan != NULL); YAML_UINT_0(def, event, emitter, "id", def->vxlan->vni); if (def->vxlan->link) YAML_STRING(def, event, emitter, "link", def->vxlan->link->id); @@ -987,7 +987,8 @@ netplan_netdef_write_yaml( filename = g_strconcat("90-NM-", netdef->backend_settings.uuid, ".yaml", NULL); else filename = g_strconcat("10-netplan-", netdef->id, ".yaml", NULL); - path = g_build_path(G_DIR_SEPARATOR_S, rootdir ?: G_DIR_SEPARATOR_S, "etc", "netplan", filename, NULL); + path = g_build_path(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, + "etc", "netplan", filename, NULL); /* Start rendering YAML output */ yaml_emitter_t emitter_data; @@ -1149,7 +1150,7 @@ netplan_state_write_yaml_file(const NetplanState* np_state, const char* filename GList* to_write = NULL; int out_fd; - path = g_build_path(G_DIR_SEPARATOR_S, rootdir ?: G_DIR_SEPARATOR_S, "etc", "netplan", filename, NULL); + path = g_build_path(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, "etc", "netplan", filename, NULL); while (iter) { NetplanNetDefinition* netdef = iter->data; @@ -1160,7 +1161,7 @@ netplan_state_write_yaml_file(const NetplanState* np_state, const char* filename } /* Remove any existing file if there is no data to write */ - gboolean write_globals = !!np_state->global_renderer; + gboolean write_globals = np_state->global_renderer != NULL; if (to_write == NULL && !write_globals) { if (unlink(path) && errno != ENOENT) { g_set_error(error, NETPLAN_FILE_ERROR, errno, "%m"); @@ -1218,7 +1219,7 @@ netplan_state_update_yaml_hierarchy(const NetplanState* np_state, const char* de g_assert(default_filename != NULL && *default_filename != '\0'); perfile_netdefs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_list_free); - default_path = g_build_path(G_DIR_SEPARATOR_S, rootdir ?: G_DIR_SEPARATOR_S, "etc", "netplan", default_filename, NULL); + default_path = g_build_path(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, "etc", "netplan", default_filename, NULL); int out_fd = -1; /* Dump global conf to the default path */ diff --git a/src/nm.c b/src/nm.c index 752506837..f23f28693 100644 --- a/src/nm.c +++ b/src/nm.c @@ -97,7 +97,7 @@ type_str(const NetplanNetDefinition* def) return "ip-tunnel"; case NETPLAN_DEF_TYPE_NM: /* needs to be overriden by passthrough "connection.type" setting */ - g_assert(def->backend_settings.passthrough); + g_assert(def->backend_settings.passthrough != NULL); GData *passthrough = def->backend_settings.passthrough; return g_datalist_get_data(&passthrough, "connection.type"); // LCOV_EXCL_START @@ -359,7 +359,7 @@ write_nm_wireguard_params(const NetplanNetDefinition* def, GKeyFile *kf, GError* if (def->wireguard_peers) { for (guint i = 0; i < def->wireguard_peers->len; i++) { NetplanWireguardPeer *peer = g_array_index (def->wireguard_peers, NetplanWireguardPeer*, i); - g_assert(peer->public_key); + g_assert(peer->public_key != NULL); g_autofree gchar* tmp_group = g_strdup_printf("wireguard-peer.%s", peer->public_key); if (peer->keepalive) @@ -510,7 +510,7 @@ maybe_generate_uuid(const NetplanNetDefinition* def) STATIC void write_nm_vxlan_parameters(const NetplanNetDefinition* def, GKeyFile* kf) { - g_assert(def->vxlan); + g_assert(def->vxlan != NULL); char uuidstr[37]; if (def->vxlan->ageing) g_key_file_set_uint64(kf, "vxlan", "ageing", def->vxlan->ageing); @@ -604,7 +604,7 @@ write_fallback_key_value(GQuark key_id, gpointer value, gpointer user_data) } else if (!has_key) { g_debug("NetworkManager: passing through fallback key: %s.%s=%s", group, k, val); g_key_file_set_comment(kf, group, k, "Netplan: passthrough setting", NULL); - } else if (!!g_strcmp0(val, old_key)) { + } else if (g_strcmp0(val, old_key) != 0) { g_debug("NetworkManager: fallback override: %s.%s=%s", group, k, val); g_key_file_set_comment(kf, group, k, "Netplan: passthrough override", NULL); } @@ -637,7 +637,7 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir, const char *match_interface_name = NULL; if (def->type == NETPLAN_DEF_TYPE_WIFI) - g_assert(ap); + g_assert(ap != NULL); else g_assert(ap == NULL); @@ -680,7 +680,7 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir, if (def->activation_mode) { /* XXX: For now NetworkManager only supports the "manual" activation * mode */ - if (!!g_strcmp0(def->activation_mode, "manual")) { + if (g_strcmp0(def->activation_mode, "manual") != 0) { g_set_error(error, NETPLAN_BACKEND_ERROR, NETPLAN_ERROR_UNSUPPORTED, "ERROR: %s: NetworkManager definitions do not support activation-mode %s\n", def->id, def->activation_mode); return FALSE; } @@ -983,11 +983,12 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir, /* Create /run/NetworkManager/ with 755 permissions if the folder is missing. * Letting the next invokation of _netplan_safe_mkdir_p_dir do it would * result in more restrictive access because of the call to umask. */ - nm_run_path = g_strjoin(G_DIR_SEPARATOR_S, rootdir ?: "", "run/NetworkManager/", NULL); + nm_run_path = g_strjoin(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : "", + "run/NetworkManager/", NULL); if (!g_file_test(nm_run_path, G_FILE_TEST_EXISTS)) _netplan_safe_mkdir_p_dir(nm_run_path); - full_path = g_strjoin(G_DIR_SEPARATOR_S, rootdir ?: "", conf_path, NULL); + full_path = g_strjoin(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : "", conf_path, NULL); /* NM connection files might contain secrets, and NM insists on tight permissions */ orig_umask = umask(077); @@ -1092,7 +1093,7 @@ netplan_state_finish_nm_write( /* Special case: manage or ignore any device of given type on empty "match: {}" stanza */ if (nd->has_match && !nd->match.driver && !nd->match.mac && !nd->match.original_name) { nm_type = type_str(nd); - g_assert(nm_type); + g_assert(nm_type != NULL); g_string_append_printf(nm_conf, "[device-netplan.%s.%s]\nmatch-device=type:%s\n" "managed=%d\n\n", netplan_def_type_name(nd->type), netdef_id, nm_type, !unmanaged); @@ -1180,8 +1181,10 @@ netplan_state_finish_nm_write( gboolean _netplan_nm_cleanup(const char* rootdir) { - g_autofree char* confpath = g_strjoin(NULL, rootdir ?: "", "/run/NetworkManager/conf.d/netplan.conf", NULL); - g_autofree char* global_manage_path = g_strjoin(NULL, rootdir ?: "", "/run/NetworkManager/conf.d/10-globally-managed-devices.conf", NULL); + g_autofree char* confpath = g_strjoin(NULL, rootdir != NULL ? rootdir : "", + "/run/NetworkManager/conf.d/netplan.conf", NULL); + g_autofree char* global_manage_path = g_strjoin(NULL, rootdir != NULL ? rootdir : "", + "/run/NetworkManager/conf.d/10-globally-managed-devices.conf", NULL); unlink(confpath); unlink(global_manage_path); _netplan_unlink_glob(rootdir, "/run/NetworkManager/system-connections/netplan-*"); diff --git a/src/openvswitch.c b/src/openvswitch.c index 472323039..09864b560 100644 --- a/src/openvswitch.c +++ b/src/openvswitch.c @@ -32,7 +32,8 @@ STATIC gboolean write_ovs_systemd_unit(const char* id, const GString* cmds, const char* rootdir, gboolean physical, gboolean cleanup, const char* dependency, GError** error) { g_autofree char* escaped_netdef_id = g_uri_escape_string(id, NULL, TRUE); - g_autofree char* link = g_strjoin(NULL, rootdir ?: "", "/run/systemd/system/systemd-networkd.service.wants/netplan-ovs-", escaped_netdef_id, ".service", NULL); + g_autofree char* link = g_strjoin(NULL, rootdir != NULL ? rootdir : "", + "/run/systemd/system/systemd-networkd.service.wants/netplan-ovs-", escaped_netdef_id, ".service", NULL); g_autofree char* path = g_strjoin(NULL, "/run/systemd/system/netplan-ovs-", escaped_netdef_id, ".service", NULL); GString* s = g_string_new("[Unit]\n"); @@ -118,8 +119,8 @@ netplan_type_is_physical(const NetplanDefType type) STATIC void write_ovs_tag_setting(const gchar* id, const char* type, const char* col, const char* key, const char* value, GString* cmds) { - g_assert(col); - g_assert(value); + g_assert(col != NULL); + g_assert(value != NULL); g_autofree char *clean_value = g_strdup(value); /* Replace " " -> "," if value contains spaces */ if (strchr(value, ' ')) { @@ -260,7 +261,7 @@ write_ovs_bridge_interfaces(const NetplanState* np_state, const NetplanNetDefini STATIC void write_ovs_protocols(const NetplanOVSSettings* ovs_settings, const gchar* bridge, GString* cmds) { - g_assert(bridge); + g_assert(bridge != NULL); GString* s = g_string_new(g_array_index(ovs_settings->protocols, char*, 0)); for (unsigned i = 1; i < ovs_settings->protocols->len; ++i) @@ -389,7 +390,7 @@ _netplan_netdef_write_ovs(const NetplanState* np_state, const NetplanNetDefiniti break; case NETPLAN_DEF_TYPE_PORT: - g_assert(def->peer); + g_assert(def->peer != NULL); dependency = def->bridge?: def->bond; if (!dependency) { g_set_error(error, NETPLAN_BACKEND_ERROR, NETPLAN_ERROR_VALIDATION, "%s: OpenVSwitch patch port needs to be assigned to a bridge/bond\n", def->id); @@ -405,7 +406,7 @@ _netplan_netdef_write_ovs(const NetplanState* np_state, const NetplanNetDefiniti break; case NETPLAN_DEF_TYPE_VLAN: - g_assert(def->vlan_link); + g_assert(def->vlan_link != NULL); dependency = def->vlan_link->id; /* Create a fake VLAN bridge */ append_systemd_cmd(cmds, OPENVSWITCH_OVS_VSCTL " --may-exist add-br %s %s %i", def->id, def->vlan_link->id, def->vlan_id) diff --git a/src/parse-nm.c b/src/parse-nm.c index 75d2b66ed..215916fd1 100644 --- a/src/parse-nm.c +++ b/src/parse-nm.c @@ -108,7 +108,7 @@ kf_matches(GKeyFile* kf, const gchar* group, const gchar* key, const gchar* matc STATIC void set_true_on_match(GKeyFile* kf, const gchar* group, const gchar* key, const gchar* match, const void* dataptr) { - g_assert(dataptr); + g_assert(dataptr != NULL); if (kf_matches(kf, group, key, match)) { *((gboolean*) dataptr) = TRUE; _kf_clear_key(kf, group, key); @@ -118,7 +118,7 @@ set_true_on_match(GKeyFile* kf, const gchar* group, const gchar* key, const gcha STATIC void keyfile_handle_generic_bool(GKeyFile* kf, const gchar* group, const gchar* key, gboolean* dataptr) { - g_assert(dataptr); + g_assert(dataptr != NULL); *dataptr = g_key_file_get_boolean(kf, group, key, NULL); _kf_clear_key(kf, group, key); } @@ -126,8 +126,8 @@ keyfile_handle_generic_bool(GKeyFile* kf, const gchar* group, const gchar* key, STATIC void keyfile_handle_generic_str(GKeyFile* kf, const gchar* group, const gchar* key, char** dataptr) { - g_assert(dataptr); - g_assert(!*dataptr); + g_assert(dataptr != NULL); + g_assert(*dataptr == NULL); *dataptr = g_key_file_get_string(kf, group, key, NULL); if (*dataptr) _kf_clear_key(kf, group, key); @@ -136,7 +136,7 @@ keyfile_handle_generic_str(GKeyFile* kf, const gchar* group, const gchar* key, c STATIC void keyfile_handle_generic_uint(GKeyFile* kf, const gchar* group, const gchar* key, guint* dataptr, guint default_value) { - g_assert(dataptr); + g_assert(dataptr != NULL); if (g_key_file_has_key(kf, group, key, NULL)) { guint data = g_key_file_get_uint64(kf, group, key, NULL); if (data != default_value) @@ -176,7 +176,7 @@ keyfile_handle_cloned_mac_address(GKeyFile *kf, NetplanNetDefinition* nd, const STATIC void parse_addresses(GKeyFile* kf, const gchar* group, GArray** ip_arr) { - g_assert(ip_arr); + g_assert(ip_arr != NULL); if (kf_matches(kf, group, "method", "manual")) { gboolean unhandled_data = FALSE; gchar *key = NULL; @@ -216,7 +216,7 @@ parse_addresses(GKeyFile* kf, const gchar* group, GArray** ip_arr) STATIC void parse_routes(GKeyFile* kf, const gchar* group, GArray** routes_arr) { - g_assert(routes_arr); + g_assert(routes_arr != NULL); NetplanIPRoute *route = NULL; gchar **split = NULL; for (unsigned i = 1;; ++i) { @@ -306,7 +306,7 @@ parse_routes(GKeyFile* kf, const gchar* group, GArray** routes_arr) STATIC void parse_dhcp_overrides(GKeyFile* kf, const gchar* group, NetplanDHCPOverrides* dataptr) { - g_assert(dataptr); + g_assert(dataptr != NULL); if ( g_key_file_get_boolean(kf, group, "ignore-auto-routes", NULL) && g_key_file_get_boolean(kf, group, "never-default", NULL)) { (*dataptr).use_routes = FALSE; @@ -322,7 +322,7 @@ parse_search_domains(GKeyFile* kf, const gchar* group, GArray** domains_arr) { // Keep "dns-search" as fallback/passthrough, as netplan cannot // differentiate between ipv4.dns-search and ipv6.dns-search - g_assert(domains_arr); + g_assert(domains_arr != NULL); gsize len = 0; gchar **split = g_key_file_get_string_list(kf, group, "dns-search", &len, NULL); if (split) { @@ -347,7 +347,7 @@ parse_search_domains(GKeyFile* kf, const gchar* group, GArray** domains_arr) STATIC void parse_nameservers(GKeyFile* kf, const gchar* group, GArray** nameserver_arr) { - g_assert(nameserver_arr); + g_assert(nameserver_arr != NULL); gchar **split = g_key_file_get_string_list(kf, group, "dns", NULL, NULL); if (split) { @@ -381,7 +381,7 @@ parse_nameservers(GKeyFile* kf, const gchar* group, GArray** nameserver_arr) STATIC void parse_dot1x_auth(GKeyFile* kf, NetplanAuthenticationSettings* auth) { - g_assert(auth); + g_assert(auth != NULL); g_autofree gchar* method = g_key_file_get_string(kf, "802-1x", "eap", NULL); if (method && g_strcmp0(method, "") != 0) { @@ -431,7 +431,7 @@ parse_dot1x_auth(GKeyFile* kf, NetplanAuthenticationSettings* auth) STATIC void parse_bond_arp_ip_targets(GKeyFile* kf, GArray **targets_arr) { - g_assert(targets_arr); + g_assert(targets_arr != NULL); g_autofree gchar *v = g_key_file_get_string(kf, "bond", "arp_ip_target", NULL); if (v) { gchar** split = g_strsplit(v, ",", -1); diff --git a/src/parse.c b/src/parse.c index a4a7f8c3a..e0a6948e4 100644 --- a/src/parse.c +++ b/src/parse.c @@ -353,7 +353,7 @@ process_mapping(NetplanParser* npp, yaml_node_t* node, const char* key_prefix, c STATIC gboolean handle_generic_guint(NetplanParser* npp, yaml_node_t* node, const void* entryptr, const void* data, GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); guint offset = GPOINTER_TO_UINT(data); guint64 v; gchar* endptr; @@ -376,7 +376,7 @@ handle_generic_guint(NetplanParser* npp, yaml_node_t* node, const void* entryptr STATIC gboolean handle_generic_str(NetplanParser* npp, yaml_node_t* node, void* entryptr, const void* data, __unused GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); guint offset = GPOINTER_TO_UINT(data); char** dest = (char**) ((void*) entryptr + offset); g_free(*dest); @@ -388,7 +388,7 @@ handle_generic_str(NetplanParser* npp, yaml_node_t* node, void* entryptr, const STATIC gboolean handle_special_macaddress_option(NetplanParser* npp, yaml_node_t* node, void* entryptr, const void* data, GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); g_assert(node->type == YAML_SCALAR_NODE); if (!_is_macaddress_special_nm_option(scalar(node)) && @@ -407,7 +407,7 @@ handle_special_macaddress_option(NetplanParser* npp, yaml_node_t* node, void* en STATIC gboolean handle_generic_mac(NetplanParser* npp, yaml_node_t* node, void* entryptr, const void* data, GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); g_assert(node->type == YAML_SCALAR_NODE); if (!_is_valid_macaddress(scalar(node))) @@ -424,7 +424,7 @@ handle_generic_mac(NetplanParser* npp, yaml_node_t* node, void* entryptr, const STATIC gboolean handle_generic_bool(NetplanParser* npp, yaml_node_t* node, void* entryptr, const void* data, GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); guint offset = GPOINTER_TO_UINT(data); gboolean v; gboolean* dest = ((void*) entryptr + offset); @@ -455,7 +455,7 @@ handle_generic_bool(NetplanParser* npp, yaml_node_t* node, void* entryptr, const STATIC gboolean handle_generic_tristate(NetplanParser* npp, yaml_node_t* node, void* entryptr, const void* data, GError** error) { - g_assert(entryptr); + g_assert(entryptr != NULL); NetplanTristate v; guint offset = GPOINTER_TO_UINT(data); NetplanTristate* dest = ((void*) entryptr + offset); @@ -1009,7 +1009,7 @@ STATIC gboolean handle_auth_key_management(NetplanParser* npp, yaml_node_t* node, __unused const void* _, GError** error) { NetplanAuthenticationSettings* auth = npp->current.auth; - g_assert(auth); + g_assert(auth != NULL); if (strcmp(scalar(node), "none") == 0) auth->key_management = NETPLAN_AUTH_KEY_MANAGEMENT_NONE; else if (strcmp(scalar(node), "psk") == 0) @@ -1048,7 +1048,7 @@ STATIC gboolean handle_auth_method(NetplanParser* npp, yaml_node_t* node, __unused const void* _, GError** error) { NetplanAuthenticationSettings* auth = npp->current.auth; - g_assert(auth); + g_assert(auth != NULL); if (strcmp(scalar(node), "tls") == 0) auth->eap_method = NETPLAN_AUTH_EAP_TLS; else if (strcmp(scalar(node), "peap") == 0) @@ -1103,7 +1103,7 @@ handle_ap_backend_settings_str(NetplanParser* npp, yaml_node_t* node, const void STATIC gboolean handle_access_point_datalist(NetplanParser* npp, yaml_node_t* node, const char* key_prefix, const void* data, GError** error) { - g_assert(npp->current.access_point); + g_assert(npp->current.access_point != NULL); gboolean ret = handle_generic_datalist(npp, node, key_prefix, npp->current.access_point, data, error); GData** list = &npp->current.access_point->backend_settings.passthrough; @@ -1152,7 +1152,7 @@ STATIC gboolean handle_access_point_password(NetplanParser* npp, yaml_node_t* node, __unused const void* _, __unused GError** error) { NetplanWifiAccessPoint *access_point = npp->current.access_point; - g_assert(access_point); + g_assert(access_point != NULL); /* shortcut for WPA-PSK */ access_point->has_auth = TRUE; if (access_point->auth.key_management == NETPLAN_AUTH_KEY_MANAGEMENT_NONE) @@ -1170,7 +1170,7 @@ handle_access_point_auth(NetplanParser* npp, yaml_node_t* node, __unused const c NetplanWifiAccessPoint *access_point = npp->current.access_point; gboolean ret; - g_assert(access_point); + g_assert(access_point != NULL); access_point->has_auth = TRUE; npp->current.auth = &access_point->auth; @@ -1184,7 +1184,7 @@ STATIC gboolean handle_access_point_mode(NetplanParser* npp, yaml_node_t* node, __unused const void* _, GError** error) { NetplanWifiAccessPoint *access_point = npp->current.access_point; - g_assert(access_point); + g_assert(access_point != NULL); if (strcmp(scalar(node), "infrastructure") == 0) access_point->mode = NETPLAN_WIFI_MODE_INFRASTRUCTURE; else if (strcmp(scalar(node), "adhoc") == 0) @@ -1200,7 +1200,7 @@ STATIC gboolean handle_access_point_band(NetplanParser* npp, yaml_node_t* node, __unused const void* _, GError** error) { NetplanWifiAccessPoint *access_point = npp->current.access_point; - g_assert(access_point); + g_assert(access_point != NULL); if (strcmp(scalar(node), "5GHz") == 0 || strcmp(scalar(node), "5G") == 0) access_point->band = NETPLAN_WIFI_BAND_5; else if (strcmp(scalar(node), "2.4GHz") == 0 || strcmp(scalar(node), "2.4G") == 0) @@ -1406,8 +1406,8 @@ const mapping_entry_handler address_option_handlers[] = { STATIC gboolean handle_generic_addresses(NetplanParser* npp, yaml_node_t* node, gboolean check_zero_prefix, GArray** ip4, GArray** ip6, GError** error) { - g_assert(ip4); - g_assert(ip6); + g_assert(ip4 != NULL); + g_assert(ip6 != NULL); for (yaml_node_item_t *i = node->data.sequence.items.start; i < node->data.sequence.items.top; i++) { g_autofree char* addr = NULL; char* prefix_len; @@ -1838,7 +1838,7 @@ handle_optional_addresses(NetplanParser* npp, yaml_node_t* node, __unused const STATIC gboolean handle_vxlan_flags(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.vxlan); + g_assert(npp->current.vxlan != NULL); assert_type(npp, node, YAML_SEQUENCE_NODE); yaml_node_t* key_node = node-1; // The YAML key of given sequence `node` @@ -1864,8 +1864,8 @@ handle_vxlan_flags(NetplanParser* npp, yaml_node_t* node, const void* data, GErr break; default: g_assert_not_reached(); // LCOV_EXCL_LINE } - g_assert(flags); - g_assert(out_ptr); + g_assert(flags != NULL); + g_assert(out_ptr != NULL); for (yaml_node_item_t *i = node->data.sequence.items.start; i < node->data.sequence.items.top; i++) { yaml_node_t *entry = yaml_document_get_node(&npp->doc, *i); @@ -1894,14 +1894,14 @@ handle_vxlan_flags(NetplanParser* npp, yaml_node_t* node, const void* data, GErr STATIC gboolean handle_vxlan_guint(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.vxlan); + g_assert(npp->current.vxlan != NULL); return handle_generic_guint(npp, node, npp->current.vxlan, data, error); } STATIC gboolean handle_vxlan_tristate(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.vxlan); + g_assert(npp->current.vxlan != NULL); return handle_generic_tristate(npp, node, npp->current.vxlan, data, error); } @@ -1941,7 +1941,7 @@ check_and_set_family(gint family, gint* dest) STATIC gboolean handle_routes_bool(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.route); + g_assert(npp->current.route != NULL); return handle_generic_bool(npp, node, npp->current.route, data, error); } @@ -2043,14 +2043,14 @@ handle_ip_rule_ip(NetplanParser* npp, yaml_node_t* node, const void* data, GErro STATIC gboolean handle_ip_rule_guint(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.ip_rule); + g_assert(npp->current.ip_rule != NULL); return handle_generic_guint(npp, node, npp->current.ip_rule, data, error); } STATIC gboolean handle_routes_guint(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.route); + g_assert(npp->current.route != NULL); return handle_generic_guint(npp, node, npp->current.route, data, error); } @@ -2595,7 +2595,7 @@ handle_tunnel_key_mapping(NetplanParser* npp, yaml_node_t* node, const char* key STATIC gboolean handle_wireguard_peer_str(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.wireguard_peer); + g_assert(npp->current.wireguard_peer != NULL); return handle_generic_str(npp, node, npp->current.wireguard_peer, data, error); } @@ -2606,7 +2606,7 @@ handle_wireguard_peer_str(NetplanParser* npp, yaml_node_t* node, const void* dat STATIC gboolean handle_wireguard_peer_guint(NetplanParser* npp, yaml_node_t* node, const void* data, GError** error) { - g_assert(npp->current.wireguard_peer); + g_assert(npp->current.wireguard_peer != NULL); return handle_generic_guint(npp, node, npp->current.wireguard_peer, data, error); } diff --git a/src/sriov.c b/src/sriov.c index ff1acb649..733f78c9b 100644 --- a/src/sriov.c +++ b/src/sriov.c @@ -30,7 +30,8 @@ STATIC gboolean write_sriov_rebind_systemd_unit(GHashTable* pfs, const char* rootdir, GError** error) { g_autofree gchar* id_escaped = NULL; - g_autofree char* link = g_strjoin(NULL, rootdir ?: "", "/run/systemd/system/multi-user.target.wants/netplan-sriov-rebind.service", NULL); + g_autofree char* link = g_strjoin(NULL, rootdir != NULL ? rootdir : "", + "/run/systemd/system/multi-user.target.wants/netplan-sriov-rebind.service", NULL); g_autofree char* path = g_strjoin(NULL, "/run/systemd/system/netplan-sriov-rebind.service", NULL); GHashTableIter iter; @@ -75,7 +76,8 @@ STATIC gboolean write_sriov_apply_systemd_unit(GHashTable* pfs, const char* rootdir, GError** error) { g_autofree gchar* id_escaped = NULL; - g_autofree char* link = g_strjoin(NULL, rootdir ?: "", "/run/systemd/system/multi-user.target.wants/netplan-sriov-apply.service", NULL); + g_autofree char* link = g_strjoin(NULL, rootdir != NULL ? rootdir : "", + "/run/systemd/system/multi-user.target.wants/netplan-sriov-apply.service", NULL); g_autofree char* path = g_strjoin(NULL, "/run/systemd/system/netplan-sriov-apply.service", NULL); GHashTableIter iter; gpointer key; diff --git a/src/types.c b/src/types.c index 93d3a6540..7a1c20ed2 100644 --- a/src/types.c +++ b/src/types.c @@ -403,7 +403,7 @@ netplan_state_new() void netplan_state_clear(NetplanState** np_state_p) { - g_assert(np_state_p); + g_assert(np_state_p != NULL); NetplanState* np_state = *np_state_p; *np_state_p = NULL; netplan_state_reset(np_state); @@ -448,14 +448,14 @@ netplan_state_reset(NetplanState* np_state) NetplanBackend netplan_state_get_backend(const NetplanState* np_state) { - g_assert(np_state); + g_assert(np_state != NULL); return np_state->backend; } guint netplan_state_get_netdefs_size(const NetplanState* np_state) { - g_assert(np_state); + g_assert(np_state != NULL); return np_state->netdefs ? g_hash_table_size(np_state->netdefs) : 0; } @@ -486,7 +486,7 @@ CLEAR_FROM_FREE(free_address_options, address_options_clear, NetplanAddressOptio NetplanNetDefinition* netplan_state_get_netdef(const NetplanState* np_state, const char* id) { - g_assert(np_state); + g_assert(np_state != NULL); if (!np_state->netdefs) return NULL; return g_hash_table_lookup(np_state->netdefs, id); @@ -495,70 +495,70 @@ netplan_state_get_netdef(const NetplanState* np_state, const char* id) ssize_t netplan_netdef_get_filepath(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size) { - g_assert(netdef); + g_assert(netdef != NULL); return netplan_copy_string(netdef->filepath, out_buffer, out_buf_size); } NetplanBackend netplan_netdef_get_backend(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->backend; } NetplanDefType netplan_netdef_get_type(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->type; } ssize_t netplan_netdef_get_id(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size) { - g_assert(netdef); + g_assert(netdef != NULL); return netplan_copy_string(netdef->id, out_buffer, out_buf_size); } NetplanNetDefinition* netplan_netdef_get_vlan_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->vlan_link; } NetplanNetDefinition* netplan_netdef_get_sriov_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->sriov_link; } NetplanNetDefinition* netplan_netdef_get_bridge_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->bridge_link; } NetplanNetDefinition* netplan_netdef_get_vrf_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->vrf_link; } NetplanNetDefinition* netplan_netdef_get_bond_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->bond_link; } NetplanNetDefinition* netplan_netdef_get_peer_link(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->peer_link; } @@ -572,56 +572,56 @@ netplan_state_has_nondefault_globals(const NetplanState* np_state) ssize_t _netplan_netdef_get_embedded_switch_mode(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size) { - g_assert(netdef); + g_assert(netdef != NULL); return netplan_copy_string(netdef->embedded_switch_mode, out_buffer, out_buf_size); } gboolean _netplan_netdef_get_delay_virtual_functions_rebind(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->sriov_delay_virtual_functions_rebind; } gboolean netplan_netdef_has_match(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->has_match; } gboolean _netplan_netdef_get_sriov_vlan_filter(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->sriov_vlan_filter; } guint _netplan_netdef_get_vlan_id(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->vlan_id; } gboolean _netplan_netdef_get_critical(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->critical; } gboolean _netplan_netdef_get_optional(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); return netdef->optional; } gboolean _netplan_netdef_is_trivial_compound_itf(const NetplanNetDefinition* netdef) { - g_assert(netdef); + g_assert(netdef != NULL); if (netdef->type == NETPLAN_DEF_TYPE_BOND) return !complex_object_is_dirty(netdef, &netdef->bond_params, sizeof(netdef->bond_params)); else if (netdef->type == NETPLAN_DEF_TYPE_BRIDGE) @@ -632,7 +632,7 @@ _netplan_netdef_is_trivial_compound_itf(const NetplanNetDefinition* netdef) ssize_t _netplan_netdef_get_bond_mode(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size) { - g_assert(netdef); + g_assert(netdef != NULL); if (netdef->type == NETPLAN_DEF_TYPE_BOND && netdef->bond_params.mode) return netplan_copy_string(netdef->bond_params.mode, out_buffer, out_buf_size); diff --git a/src/util.c b/src/util.c index 0526a88dc..7957644ef 100644 --- a/src/util.c +++ b/src/util.c @@ -80,7 +80,7 @@ void _netplan_g_string_free_to_file(GString* s, const char* rootdir, const char* GError* error = NULL; path_suffix = g_strjoin(NULL, path, suffix, NULL); - full_path = g_build_path(G_DIR_SEPARATOR_S, rootdir ?: G_DIR_SEPARATOR_S, path_suffix, NULL); + full_path = g_build_path(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, path_suffix, NULL); _netplan_safe_mkdir_p_dir(full_path); if (!g_file_set_contents(full_path, contents, -1, &error)) { /* the mkdir() just succeeded, there is no sensible @@ -104,7 +104,7 @@ void _netplan_g_string_free_to_file_with_permissions(GString* s, const char* roo int ret = 0; path_suffix = g_strjoin(NULL, path, suffix, NULL); - full_path = g_build_path(G_DIR_SEPARATOR_S, rootdir ?: G_DIR_SEPARATOR_S, path_suffix, NULL); + full_path = g_build_path(G_DIR_SEPARATOR_S, rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, path_suffix, NULL); _netplan_safe_mkdir_p_dir(full_path); if (!g_file_set_contents_full(full_path, contents, -1, G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING, mode, &error)) { /* the mkdir() just succeeded, there is no sensible @@ -144,7 +144,7 @@ _netplan_unlink_glob(const char* rootdir, const char* _glob) { glob_t gl; int rc; - g_autofree char* rglob = g_strjoin(NULL, rootdir ?: "", G_DIR_SEPARATOR_S, _glob, NULL); + g_autofree char* rglob = g_strjoin(NULL, rootdir != NULL ? rootdir : "", G_DIR_SEPARATOR_S, _glob, NULL); rc = glob(rglob, GLOB_BRACE, NULL, &gl); if (rc != 0 && rc != GLOB_NOMATCH) { @@ -166,7 +166,7 @@ int _netplan_find_yaml_glob(const char* rootdir, glob_t* out_glob) { int rc; g_autofree char* rglob = g_build_path(G_DIR_SEPARATOR_S, - rootdir ?: G_DIR_SEPARATOR_S, + rootdir != NULL ? rootdir : G_DIR_SEPARATOR_S, "{lib,etc,run}/netplan/*.yaml", NULL); rc = glob(rglob, GLOB_BRACE, NULL, out_glob); if (rc != 0 && rc != GLOB_NOMATCH) { @@ -1014,20 +1014,23 @@ netplan_netdef_match_interface(const NetplanNetDefinition* netdef, const char* n return !g_strcmp0(name, netdef->id); if (netdef->match.mac) { - if (g_ascii_strcasecmp(netdef->match.mac ?: "", mac ?: "")) + if (g_ascii_strcasecmp(netdef->match.mac != NULL ? netdef->match.mac : "", mac != NULL ? mac : "")) { return FALSE; + } } if (netdef->match.original_name) { - if (!name || fnmatch(netdef->match.original_name, name, 0)) + if (!name || fnmatch(netdef->match.original_name, name, 0)) { return FALSE; + } } if (netdef->match.driver) { gboolean matches_driver = FALSE; char** tokens; - if (!driver_name) + if (!driver_name) { return FALSE; + } tokens = g_strsplit(netdef->match.driver, "\t", -1); for (char** it = tokens; *it; it++) { if (fnmatch(*it, driver_name, 0) == 0) { @@ -1116,7 +1119,7 @@ is_multicast_address(const char* address) void netplan_state_iterator_init(const NetplanState* np_state, NetplanStateIterator* iter) { - g_assert(iter); + g_assert(iter != NULL); RealStateIter* _iter = (RealStateIter*) iter; _iter->next = g_list_first(np_state->netdefs_ordered); }