On Tue, 9 Dec 2025 at 17:43, Cédric Le Goater <[email protected]> wrote:
>
> A recent change in glibc 2.42.9000 [1] changes the return type of
> strstr() and other string functions to be 'const char *' when the
> input is a 'const char *'.
>
> This breaks the build in various files with errors such as :
>
>   error: initialization discards 'const' qualifier from pointer target type 
> [-Werror=discarded-qualifiers]
>     208 |         char *pidstr = strstr(filename, "%");
>         |                        ^~~~~~
>
> Fix this by changing the type of the variables that store the result
> of these functions to 'const char *'.
>
> [1] 
> https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
>
> Signed-off-by: Cédric Le Goater <[email protected]>
> ---
>
>  Most changes are straight forward apart from vubr_parse_host_port.
>  Please check.

> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -744,7 +744,7 @@ vubr_run(VubrDev *dev)
>  }
>
>  static int
> -vubr_parse_host_port(const char **host, const char **port, const char *buf)
> +vubr_parse_host_port(const char **host, const char **port, char *buf)
>  {
>      char *p = strchr(buf, ':');

The other changes are all fine; this one's a little trickier.

The callers of this function pass the getopt() global 'optarg' as the
buf argument. That library interface is not specific about whether
modifying the string is permitted. In practice the strings will
be from the argv[] array, which you apparently are allowed to
modify per C99.

So I think this change is OK, but given that all we're doing
here is splitting the string on ':' we could also rewrite this
function (untested!):

static int
vubr_parse_host_port(const char **host, const char **port, const char *buf)
{
    g_auto(GStrv) tokens = g_strsplit(buf, ":", 2);
    if (!tokens[0] || !tokens[1])) {
        return -1;
    }
    *host = g_steal_pointer(&tokens[0]);
    *port = g_steal_pointer(&tokens[1]);
    return 0;
}

There's also a more minimal tweak we could do instead where instead
of writing a '\0' purely so we can use strdup() to copy the part
before the ':' we instead use strndup(). But I figured that using
the glib string-splitting routine was neater.

thanks
-- PMM

Reply via email to