merge: branch 'jv/fix-rawhide-build'

all: fix NM compilation on rawhide

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2321
This commit is contained in:
Jan Vaclav 2025-12-04 12:01:18 +00:00
commit 0b61924048
15 changed files with 63 additions and 44 deletions

View file

@ -32,11 +32,11 @@ ip4_process_dhcpcd_rfc3442_routes(const char *iface,
in_addr_t address, in_addr_t address,
guint32 *out_gwaddr) guint32 *out_gwaddr)
{ {
gs_free const char **routes = NULL; gs_free char **routes = NULL;
const char **r; char **r;
gboolean have_routes = FALSE; gboolean have_routes = FALSE;
routes = nm_strsplit_set(str, " "); routes = (char **) nm_strsplit_set(str, " ");
if (!routes) if (!routes)
return FALSE; return FALSE;

View file

@ -1510,8 +1510,8 @@ _domain_track_is_shadowed(GHashTable *ht,
const char **out_parent, const char **out_parent,
int *out_parent_priority) int *out_parent_priority)
{ {
char *parent; const char *parent;
int parent_priority; int parent_priority;
if (!ht) if (!ht)
return FALSE; return FALSE;

View file

@ -160,7 +160,7 @@ parse_connection_from_shadowed_file(const char *path, GError **error)
{ {
nm_auto_unref_keyfile GKeyFile *keyfile = NULL; nm_auto_unref_keyfile GKeyFile *keyfile = NULL;
gs_free char *base_dir = NULL; gs_free char *base_dir = NULL;
char *sep; const char *sep;
keyfile = g_key_file_new(); keyfile = g_key_file_new();
if (!g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, error)) if (!g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, error))

View file

@ -123,7 +123,8 @@ software_add(NMLinkType link_type, const char *name)
gboolean bond0_exists = !!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "bond0"); gboolean bond0_exists = !!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "bond0");
int r; int r;
const NMPlatformLnkBond nm_platform_lnk_bond_default = { const NMPlatformLnkBond nm_platform_lnk_bond_default = {
.mode = nmtst_rand_select(3, 1), .mode = nmtst_rand_select(3, 1),
.use_carrier = 1,
}; };
r = nm_platform_link_bond_add(NM_PLATFORM_GET, name, &nm_platform_lnk_bond_default, NULL); r = nm_platform_link_bond_add(NM_PLATFORM_GET, name, &nm_platform_lnk_bond_default, NULL);

View file

@ -77,7 +77,7 @@ get_full_file_path(const char *ifcfg_path, const char *file_path)
{ {
const char *base = file_path; const char *base = file_path;
gs_free char *dirname = NULL; gs_free char *dirname = NULL;
char *p; const char *p;
g_return_val_if_fail(ifcfg_path != NULL, NULL); g_return_val_if_fail(ifcfg_path != NULL, NULL);
g_return_val_if_fail(file_path != NULL, NULL); g_return_val_if_fail(file_path != NULL, NULL);

View file

@ -212,18 +212,19 @@ validate_type_utf8(const struct Opt *opt, const char *value, const guint32 len)
} }
static gboolean static gboolean
validate_type_keyword(const struct Opt *opt, const char *value, const guint32 len) validate_type_keyword(const struct Opt *opt, const char *value_in, const guint32 len)
{ {
gs_free char *value_free = NULL; gs_free char *value_free = NULL;
char *value;
nm_assert(opt); nm_assert(opt);
nm_assert(value); nm_assert(value_in);
/* Allow everything */ /* Allow everything */
if (!opt->str_allowed) if (!opt->str_allowed)
return TRUE; return TRUE;
value = nm_strndup_a(300, value, len, &value_free); value = nm_strndup_a(300, value_in, len, &value_free);
/* validate each space-separated word in 'value' */ /* validate each space-separated word in 'value' */

View file

@ -483,8 +483,8 @@ nm_utils_validate_shared_dhcp_range(const char *shared_dhcp_range,
GPtrArray *addresses, GPtrArray *addresses,
GError **error) GError **error)
{ {
char *start_address_str; const char *start_address_str;
char *end_address_str; const char *end_address_str;
NMIPAddress *interface_address_with_prefix; NMIPAddress *interface_address_with_prefix;
NMIPAddr interface_address; NMIPAddr interface_address;
NMIPAddr start_address; NMIPAddr start_address;
@ -825,7 +825,7 @@ nm_dns_uri_parse(int addr_family, const char *str, NMDnsServer *dns, GError **er
addr = nm_strndup_a(100, addr_port, end - addr_port, &addr_heap); addr = nm_strndup_a(100, addr_port, end - addr_port, &addr_heap);
/* IPv6 link-local scope-id */ /* IPv6 link-local scope-id */
perc = strchr(addr, '%'); perc = (char *) strchr(addr, '%');
if (perc) { if (perc) {
*perc = '\0'; *perc = '\0';
if (g_strlcpy(dns->interface, perc + 1, sizeof(dns->interface)) if (g_strlcpy(dns->interface, perc + 1, sizeof(dns->interface))

View file

@ -472,17 +472,17 @@ nm_bridge_vlan_to_str(const NMBridgeVlan *vlan, GError **error)
NMBridgeVlan * NMBridgeVlan *
nm_bridge_vlan_from_str(const char *str, GError **error) nm_bridge_vlan_from_str(const char *str, GError **error)
{ {
NMBridgeVlan *vlan = NULL; NMBridgeVlan *vlan = NULL;
gs_free const char **tokens = NULL; gs_free char **tokens = NULL;
guint i, vid_start, vid_end = 0; guint i, vid_start, vid_end = 0;
gboolean pvid = FALSE; gboolean pvid = FALSE;
gboolean untagged = FALSE; gboolean untagged = FALSE;
char *c; char *c;
g_return_val_if_fail(str, NULL); g_return_val_if_fail(str, NULL);
g_return_val_if_fail(!error || !*error, NULL); g_return_val_if_fail(!error || !*error, NULL);
tokens = nm_utils_escaped_tokens_split(str, NM_ASCII_SPACES); tokens = (char **) nm_utils_escaped_tokens_split(str, NM_ASCII_SPACES);
if (!tokens || !tokens[0]) { if (!tokens || !tokens[0]) {
g_set_error_literal(error, g_set_error_literal(error,
NM_CONNECTION_ERROR, NM_CONNECTION_ERROR,

View file

@ -4495,7 +4495,7 @@ nm_range_from_str(const char *str, GError **error)
gs_free char *str_free = NULL; gs_free char *str_free = NULL;
guint64 start; guint64 start;
guint64 end = 0; guint64 end = 0;
char *c; const char *c;
g_return_val_if_fail(str, NULL); g_return_val_if_fail(str, NULL);
g_return_val_if_fail(!error || !*error, NULL); g_return_val_if_fail(!error || !*error, NULL);

View file

@ -25,15 +25,18 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
* Normal bsearch requires base to be nonnull. Here were require * Normal bsearch requires base to be nonnull. Here were require
* that only if nmemb > 0. * that only if nmemb > 0.
*/ */
static inline void* bsearch_safe(const void *key, const void *base, static inline void* bsearch_safe_internal(const void *key, const void *base,
size_t nmemb, size_t size, comparison_fn_t compar) { size_t nmemb, size_t size, comparison_fn_t compar) {
if (nmemb <= 0) if (nmemb <= 0)
return NULL; return NULL;
assert(base); assert(base);
return bsearch(key, base, nmemb, size, compar); return (void*) bsearch(key, base, nmemb, size, compar);
} }
#define bsearch_safe(key, base, nmemb, size, compar) \
const_generic((base), bsearch_safe_internal(key, base, nmemb, size, compar))
#define typesafe_bsearch(k, b, n, func) \ #define typesafe_bsearch(k, b, n, func) \
({ \ ({ \
const typeof((b)[0]) *_k = k; \ const typeof((b)[0]) *_k = k; \

View file

@ -1470,7 +1470,7 @@ ssize_t strlevenshtein(const char *x, const char *y) {
return t1[yl]; return t1[yl];
} }
char* strrstr(const char *haystack, const char *needle) { char* strrstr_internal(const char *haystack, const char *needle) {
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */ /* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
if (!haystack || !needle) if (!haystack || !needle)
@ -1479,7 +1479,7 @@ char* strrstr(const char *haystack, const char *needle) {
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the /* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
* last char, not before. */ * last char, not before. */
if (*needle == 0) if (*needle == 0)
return strchr(haystack, 0); return (char*) strchr(haystack, 0);
for (const char *p = strstr(haystack, needle), *q; p; p = q) { for (const char *p = strstr(haystack, needle), *q; p; p = q) {
q = strstr(p + 1, needle); q = strstr(p + 1, needle);

View file

@ -27,24 +27,28 @@
#define URI_UNRESERVED ALPHANUMERICAL "-._~" /* [RFC3986] */ #define URI_UNRESERVED ALPHANUMERICAL "-._~" /* [RFC3986] */
#define URI_VALID URI_RESERVED URI_UNRESERVED /* [RFC3986] */ #define URI_VALID URI_RESERVED URI_UNRESERVED /* [RFC3986] */
static inline char* strstr_ptr(const char *haystack, const char *needle) { static inline char* strstr_ptr_internal(const char *haystack, const char *needle) {
if (!haystack || !needle) if (!haystack || !needle)
return NULL; return NULL;
return strstr(haystack, needle); return (char*) strstr(haystack, needle);
} }
static inline char* strstrafter(const char *haystack, const char *needle) { #define strstr_ptr(haystack, needle) \
char *p; const_generic(haystack, strstr_ptr_internal(haystack, needle))
static inline char* strstrafter_internal(const char *haystack, const char *needle) {
/* Returns NULL if not found, or pointer to first character after needle if found */ /* Returns NULL if not found, or pointer to first character after needle if found */
p = strstr_ptr(haystack, needle); char *p = (char*) strstr_ptr(haystack, needle);
if (!p) if (!p)
return NULL; return NULL;
return p + strlen(needle); return p + strlen(needle);
} }
#define strstrafter(haystack, needle) \
const_generic(haystack, strstrafter_internal(haystack, needle))
static inline const char* strnull(const char *s) { static inline const char* strnull(const char *s) {
return s ?: "(null)"; return s ?: "(null)";
} }
@ -300,6 +304,8 @@ bool version_is_valid_versionspec(const char *s);
ssize_t strlevenshtein(const char *x, const char *y); ssize_t strlevenshtein(const char *x, const char *y);
char* strrstr(const char *haystack, const char *needle); char* strrstr_internal(const char *haystack, const char *needle);
#define strrstr(haystack, needle) \
const_generic(haystack, strrstr_internal(haystack, needle))
size_t str_common_prefix(const char *a, const char *b); size_t str_common_prefix(const char *a, const char *b);

View file

@ -511,4 +511,11 @@ assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1);
#define PROJECT_FILE (&__FILE__[STRLEN(RELATIVE_SOURCE_PATH) + 1]) #define PROJECT_FILE (&__FILE__[STRLEN(RELATIVE_SOURCE_PATH) + 1])
#else /* NM_IGNORED */ #else /* NM_IGNORED */
#define PROJECT_FILE __FILE__ #define PROJECT_FILE __FILE__
#endif /* NM_IGNORED */ #endif /* NM_IGNORED */
/* This macro is used to have a const-returning and non-const returning version of a function based on
* whether its first argument is const or not (e.g. strstr()). */
#define const_generic(ptr, call) \
_Generic(0 ? (ptr) : (void*) 1, \
const void*: (const typeof(*call)*) (call), \
void*: (call))

View file

@ -92,7 +92,8 @@ _subsystem_split(const char *subsystem_full,
const char **out_devtype, const char **out_devtype,
char **to_free) char **to_free)
{ {
char *tmp, *s; char *tmp;
const char *s;
nm_assert(subsystem_full); nm_assert(subsystem_full);
nm_assert(out_subsystem); nm_assert(out_subsystem);
@ -101,12 +102,12 @@ _subsystem_split(const char *subsystem_full,
s = strstr(subsystem_full, "/"); s = strstr(subsystem_full, "/");
if (s) { if (s) {
tmp = g_strdup(subsystem_full); tmp = g_strdup(subsystem_full);
s = &tmp[s - subsystem_full]; tmp[s - subsystem_full] = '\0';
*s = '\0'; s = &tmp[s - subsystem_full];
*out_subsystem = tmp; *out_subsystem = tmp;
*out_devtype = &s[1]; *out_devtype = &s[1];
*to_free = tmp; *to_free = tmp;
} else { } else {
*out_subsystem = subsystem_full; *out_subsystem = subsystem_full;
*out_devtype = NULL; *out_devtype = NULL;

View file

@ -1177,7 +1177,7 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
{ {
const char *nettype; const char *nettype;
const char *subchannels[4] = {0, 0, 0, 0}; const char *subchannels[4] = {0, 0, 0, 0};
const char *tmp; char *tmp;
gs_free char *ifname = NULL; gs_free char *ifname = NULL;
gs_free char *str_subchannels = NULL; gs_free char *str_subchannels = NULL;
const char *prefix; const char *prefix;
@ -1248,8 +1248,8 @@ reader_parse_rd_znet(Reader *reader, char *argument, gboolean net_ifnames)
NULL); NULL);
while ((tmp = get_word(&argument, ',')) != NULL) { while ((tmp = get_word(&argument, ',')) != NULL) {
const char *key; char *key;
char *val; char *val;
val = strchr(tmp, '='); val = strchr(tmp, '=');
if (!val) { if (!val) {