Skip to contentSkip to conversation

vpn: Fix issue with const return value from strrchr

PATCH Applied Rudi Heitbaum 1 participant 1 message Feb 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 vpn: Fix issue with const return value from strrchr

When compiling with recent gcc and glibc-2.43 the --Wdiscarded-qualifiers warning occurs because with ISO C23, the function strrrchr that return pointers into their input arrays now have definitions as macros that return a pointer to a const-qualified type when the input argument is a pointer to a const-qualified type.

../plugins/vpn.c: In function 'get_ident': ../plugins/vpn.c:170:13: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 170 | pos = strrchr(path, '/'); | ^

---
 plugins/vpn.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
plugins/vpn.c +4 -4
index 332d8e83..1a6b0194 100644
@@ -160,9 +160,9 @@ static const char *get_string(struct connman_provider *provider,
 	return g_hash_table_lookup(data->setting_strings, key);
 }
 
-static char *get_ident(const char *path)
+static const char *get_ident(const char *path)
 {
-	char *pos;
+	const char *pos;
 
 	if (*path != '/')
 		return NULL;
@@ -665,7 +665,7 @@ static void add_connection(const char *path, DBusMessageIter *properties,
 {
 	struct connection_data *data;
 	int err;
-	char *ident = get_ident(path);
+	const char *ident = get_ident(path);
 	bool found = false;
 
 	data = g_hash_table_lookup(vpn_connections, ident);
@@ -1092,7 +1092,7 @@ static void configuration_create_reply(DBusPendingCall *call, void *user_data)
 	DBusMessageIter iter;
 	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
 	const char *path;
-	char *ident;
+	const char *ident;
 	struct connection_data *data;
 	struct config_create_data *cb_data = user_data;
 
Signature · 1 line
2.51.0