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
This commit is contained in:
committed by
Tobias Brunner
parent
77e89bdcdc
commit
d6b1574e2a
@@ -29,7 +29,7 @@ char* translate(char *str, const char *from, const char *to)
|
|||||||
}
|
}
|
||||||
while (pos && *pos)
|
while (pos && *pos)
|
||||||
{
|
{
|
||||||
char *match;
|
const char *match;
|
||||||
if ((match = strchr(from, *pos)) != NULL)
|
if ((match = strchr(from, *pos)) != NULL)
|
||||||
{
|
{
|
||||||
*pos = to[match - from];
|
*pos = to[match - from];
|
||||||
@@ -70,7 +70,7 @@ char* strreplace(const char *str, const char *search, const char *replace)
|
|||||||
{
|
{
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
}
|
}
|
||||||
found = strstr(str, search);
|
found = (char*)strstr(str, search);
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
return (char*)str;
|
return (char*)str;
|
||||||
@@ -86,7 +86,7 @@ char* strreplace(const char *str, const char *search, const char *replace)
|
|||||||
dst += rlen;
|
dst += rlen;
|
||||||
pos = found + slen;
|
pos = found + slen;
|
||||||
}
|
}
|
||||||
while ((found = strstr(pos, search)));
|
while ((found = (char*)strstr(pos, search)));
|
||||||
strcpy(dst, pos);
|
strcpy(dst, pos);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user