dns: fix discards 'const' qualifier from pointer target type

Since glibc-2.43:

For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return pointers
into their input arrays now have definitions as macros that return a
pointer to a const-qualified type when the input argument is a pointer
to a const-qualified type.

fixes:
    src/openvpn/dns.c: In function 'dns_server_addr_parse':
    src/openvpn/dns.c:67:25: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       67 |     char *first_colon = strchr(addr, ':');
          |                         ^~~~~~
    src/openvpn/dns.c:68:24: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       68 |     char *last_colon = strrchr(addr, ':');
          |                        ^~~~~~~

Change-Id: I262705189edfbd9aa9a32bcd712840fffa592435
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1542
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20260218214738.27158-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35730.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 0157e7fb8a)
This commit is contained in:
Rudi Heitbaum 2026-02-18 22:47:33 +01:00 committed by Gert Doering
parent b5087dcf3f
commit 7cf6e1f8dc

View file

@ -38,7 +38,7 @@
* @return True if parsing was successful
*/
static bool
dns_server_port_parse(in_port_t *port, char *port_str)
dns_server_port_parse(in_port_t *port, const char *port_str)
{
char *endptr;
errno = 0;
@ -64,8 +64,8 @@ dns_server_addr_parse(struct dns_server *server, const char *addr)
in_port_t port = 0;
sa_family_t af;
char *first_colon = strchr(addr, ':');
char *last_colon = strrchr(addr, ':');
const char *first_colon = strchr(addr, ':');
const char *last_colon = strrchr(addr, ':');
if (!first_colon || first_colon == last_colon)
{
@ -86,7 +86,7 @@ dns_server_addr_parse(struct dns_server *server, const char *addr)
if (addr[0] == '[')
{
addr += 1;
char *bracket = last_colon - 1;
const char *bracket = last_colon - 1;
if (*bracket != ']' || bracket == addr || !dns_server_port_parse(&port, last_colon + 1))
{
return false;