Skip to contentSkip to conversation

vpn-provider: 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 2/5 vpn-provider: 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.

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

---
 vpn/vpn-provider.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
vpn/vpn-provider.c +3 -3
index 4bcb8373..dafdaffa 100644
@@ -1648,9 +1648,9 @@ static void connection_removed_signal(struct vpn_provider *provider)
 	dbus_message_unref(signal);
 }
 
-static char *get_ident(const char *path)
+static const char *get_ident(const char *path)
 {
-	char *pos;
+	const char *pos;
 
 	if (*path != '/')
 		return NULL;
@@ -1665,7 +1665,7 @@ static char *get_ident(const char *path)
 int __vpn_provider_remove(const char *path)
 {
 	struct vpn_provider *provider;
-	char *ident;
+	const char *ident;
 
 	DBG("path %s", path);
 
Signature · 1 line
2.51.0