On 1/28/26 9:10 PM, Kevin Traynor via dev wrote:
> glibc 2.42 has const-preserving functions.
> 
> This leads to warnings when there is a const argument and an assignment
> to a non-const variable. Example with GCC 16.0.1 and glibc 2.43 on
> Fedora Rawhide.
> 
> lib/daemon-unix.c: In function 'daemon_set_new_user':
> lib/daemon-unix.c:984:17:
> error: initialization discards 'const' qualifier from pointer target type
> [-Werror=discarded-qualifiers]
>   984 |     char *pos = strchr(user_spec, ':');
>       |                 ^~~~~~
> 
> Fix by using const variables.
> 
> Signed-off-by: Kevin Traynor <[email protected]>
> ---
>  lib/daemon-unix.c    | 4 ++--
>  lib/odp-util.c       | 4 ++--
>  lib/stream-ssl.c     | 2 +-
>  ovsdb/ovsdb-server.c | 9 +++++----
>  4 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
> index 86adc9c19..52f977ec8 100644
> --- a/lib/daemon-unix.c
> +++ b/lib/daemon-unix.c
> @@ -982,5 +982,5 @@ void
>  daemon_set_new_user(const char *user_spec)
>  {
> -    char *pos = strchr(user_spec, ':');
> +    const char *pos = strchr(user_spec, ':');
>      size_t init_bufsize, bufsize;
>  
> @@ -1037,5 +1037,5 @@ daemon_set_new_user(const char *user_spec)
>  
>      if (pos) {
> -        char *grpstr = pos + 1;
> +        const char *grpstr = pos + 1;
>          grpstr += strspn(grpstr, " \t\r\n");
>  
> diff --git a/lib/odp-util.c b/lib/odp-util.c
> index e004b7964..841f7d9d4 100644
> --- a/lib/odp-util.c
> +++ b/lib/odp-util.c
> @@ -1986,5 +1986,5 @@ scan_ct_nat(const char *s, struct ct_nat_params *p)
>  
>          if (ovs_scan_len(s, &n, "(")) {
> -            char *end;
> +            const char *end;
>              int end_n;
>  
> @@ -2107,5 +2107,5 @@ parse_conntrack_action(const char *s_, struct ofpbuf 
> *actions)
>          bool have_nat = false;
>          size_t start;
> -        char *end;
> +        const char *end;

nit: Should move this up to preserve the reverse x-mass tree ordering.

>  
>          memset(&ct_label, 0, sizeof(ct_label));
> diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
> index 4470bca54..c8eb26b2a 100644
> --- a/lib/stream-ssl.c
> +++ b/lib/stream-ssl.c
> @@ -1290,5 +1290,5 @@ stream_ssl_set_protocols(const char *arg)
>          {"TLSv1.3", TLS1_3_VERSION,      false},
>      };
> -    char *dash = strchr(arg, '-');
> +    const char *dash = strchr(arg, '-');
>      bool or_later = false;
>      int len = strlen(arg);
> diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
> index 86b0dc7b8..d4ed9ab32 100644
> --- a/ovsdb/ovsdb-server.c
> +++ b/ovsdb/ovsdb-server.c
> @@ -420,4 +420,5 @@ parse_relay_args(const char *arg, char **name, char 
> **remote)
>      const char *relay_prefix = "relay:";
>      const int relay_prefix_len = strlen(relay_prefix);
> +    const char *remote_colon;

nit: I wonder if a 'second_colon' would be an easier to understand name.
But I'm not sure about this one.

>      bool is_relay;
>  
> @@ -427,13 +428,13 @@ parse_relay_args(const char *arg, char **name, char 
> **remote)
>      }
>  
> -    *remote = strchr(arg + relay_prefix_len, ':');
> +    remote_colon = strchr(arg + relay_prefix_len, ':');
>  
> -    if (!*remote || (*remote)[0] == '\0') {
> +    if (!remote_colon || (remote_colon)[0] == '\0') {

nit: No need for parenthesis around the name anymore.

There also may be a bug here. :)  We should be checking the [1] and
not the [0], right?  As if strchr() didn't return NULL, then it points
to the colon itself, i.e. the [0] will always be ':'.  Should be a
separate patch though.

>          *remote = NULL;
>          return false;
>      }
>      arg += relay_prefix_len;
> -    *name = xmemdup0(arg, *remote - arg);
> -    *remote = xstrdup(*remote + 1);
> +    *name = xmemdup0(arg, remote_colon - arg);
> +    *remote = xstrdup(remote_colon + 1);
>      return true;
>  }

Thanks, Kevin!  Beside the couple of nits above, the change
looks good to me.  And it fixes the build on f44 for me.
I suppose, we'll need to backport that down to 3.3.

Acked-by: Ilya Maximets <[email protected]>
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to