Skip to contentSkip to conversation

scripts: Fix issue with const return value from strchr

PATCH New Grant Erickson 1 participant 1 message Nov 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: Fix issue with const return value from strchr

When compiling with recent GCC or clang/LLVM and glibc 2.43 or later, such as on Ubuntu 26.04 ('Resolute'), the -Wdiscarded-qualifiers (GCC) or -Wincompatible-pointer-types-discards-qualifiers (clang/LLVM) warning occurs, and is an error when --enable-maintainer-mode is asserted, because with ISO C23, the function strchr, which returns a pointer into its input array, is now defined as a macro that returns a pointer to a const-qualified type when the input argument is a pointer to a const-qualified type:

scripts/openvpn-script.c:52:15: error: assignment discards 'const'
qualifier from pointer target type [-Werror=discarded-qualifiers]
scripts/vpn-script.c:51:15: error: assignment discards 'const'
qualifier from pointer target type [-Werror=discarded-qualifiers]

In both scripts, 'append' writes a null terminator through the pointer returned by strchr, splitting each 'environ' entry in place into a key and value. So, rather than casting the qualifier away, 'append' is made to say what it does and takes a non-const 'pattern'. Its only callers pass 'environ' entries, which are 'char *'.

---
 scripts/openvpn-script.c | 2 +-
 scripts/vpn-script.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
scripts/openvpn-script.c +1 -1
index 6ba0d292b28d..d949556428d4 100644
@@ -43,7 +43,7 @@ static void print(const char *format, ...)
 	va_end(ap);
 }
 
-static void append(DBusMessageIter *dict, const char *pattern)
+static void append(DBusMessageIter *dict, char *pattern)
 {
 	DBusMessageIter entry;
 	const char *key, *value;
scripts/vpn-script.c +1 -1
index 6e020e92147c..6d5a3acf7874 100644
@@ -42,7 +42,7 @@ static void print(const char *format, ...)
 	va_end(ap);
 }
 
-static void append(DBusMessageIter *dict, const char *pattern)
+static void append(DBusMessageIter *dict, char *pattern)
 {
 	DBusMessageIter entry;
 	const char *key, *value;
Signature · 1 line
2.52.0