From d6b1574e2aeb1fb575eba82967912d1e175862f0 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Thu, 26 Feb 2026 11:25:27 -0600 Subject: [PATCH] string: Fix -Werror=discarded-qualifiers with GCC 15 GCC 15 tightened its built-in declarations for strchr() and strstr() so that they now propagate const from their first argument, triggering -Werror=discarded-qualifiers on three assignments in string.c: translate(): char *match = strchr(from, *pos) `from` is const char *, so the result of strchr() is const char *. `match` is only used for pointer arithmetic (match - from), so declaring it const char * is correct and safe. strreplace(): found = strstr(str, search) [line ~73] found = strstr(pos, search) [line ~89, while condition] `str`/`pos` are derived from a const char * parameter, so strstr() returns const char *. `found` is used as a mutable char * later (pos = found + slen), consistent with the existing (char*) casts already used throughout this function for the same reason. Add explicit (char*) casts to match the established pattern. Closes strongswan/strongswan#3015 --- src/libstrongswan/utils/utils/string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstrongswan/utils/utils/string.c b/src/libstrongswan/utils/utils/string.c index 8c5006bcc..20c76ca33 100644 --- a/src/libstrongswan/utils/utils/string.c +++ b/src/libstrongswan/utils/utils/string.c @@ -29,7 +29,7 @@ char* translate(char *str, const char *from, const char *to) } while (pos && *pos) { - char *match; + const char *match; if ((match = strchr(from, *pos)) != NULL) { *pos = to[match - from]; @@ -70,7 +70,7 @@ char* strreplace(const char *str, const char *search, const char *replace) { len = strlen(str); } - found = strstr(str, search); + found = (char*)strstr(str, search); if (!found) { return (char*)str; @@ -86,7 +86,7 @@ char* strreplace(const char *str, const char *search, const char *replace) dst += rlen; pos = found + slen; } - while ((found = strstr(pos, search))); + while ((found = (char*)strstr(pos, search))); strcpy(dst, pos); return res; }