]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: tools: fix C23 incompatible strrchr usage
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 Aug 2026 09:00:19 +0000 (11:00 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 Aug 2026 09:11:11 +0000 (11:11 +0200)
Fix the following warning by ensuring strrchr() return type is set to
'const char *' if its input is declared as such.

src/tools.c: In function ‘str2net’:
src/tools.c:1618:16: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 1618 |         if ((c = strrchr(str, '/')) != NULL) {
      |                ^

This build warning was introduced by the following patch.

  9bc6c4d18c2ea9836c171977c1c7c2979ecbb132
  OPTIM: tools/str2net: only duplicate the string when a slash is present

This change is required since C23, as strrchr(), along other functions
which accept a const-qualified pointer without returning a const type
are now declared as macro with generics to preserve the const qualifier.

See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3020.pdf for
details.

No need to backport, unless the above patch is.

src/tools.c

index 7425c4de06e25fb2715b7d8b8a7e66f5a605c3e7..08dbc78d366cc261e356f0b9663b1fc68552d35a 100644 (file)
@@ -1609,7 +1609,7 @@ int str2net(const char *str, int resolve, struct in_addr *addr, struct in_addr *
 {
        __label__ out_free, out_err;
        char *s = NULL;
-       char *c;
+       const char *c;
        int ret_val;
 
        memset(mask, 0, sizeof(*mask));
@@ -1660,7 +1660,7 @@ int str2net(const char *str, int resolve, struct in_addr *addr, struct in_addr *
 int str62net(const char *str, struct in6_addr *addr, unsigned char *mask)
 {
        char *s = NULL;
-       char *c;
+       const char *c;
        int ret_val = 0;
        char *err;
        unsigned long len = 128;