unix: fix discard const

Do not cast const char to char unnecessarily. Refactor function to use
char s only when slash is in the path.

Fixes:

[6/73] Building C object CMakeFiles/uv.dir/src/inet.c.o
../src/inet.c: In function 'uv_inet_pton':
../src/inet.c:157:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  157 |     p = strchr(src, '%');
      |       ^

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
This commit is contained in:
Rudi Heitbaum 2026-03-05 03:02:24 +00:00 committed by Saúl Ibarra Corretgé
parent 568470a2ef
commit 5243d19134

View File

@ -151,19 +151,19 @@ int uv_inet_pton(int af, const char* src, void* dst) {
case AF_INET:
return (inet_pton4(src, dst));
case AF_INET6: {
int len;
char tmp[UV__INET6_ADDRSTRLEN], *s, *p;
s = (char*) src;
const char *p;
p = strchr(src, '%');
if (p != NULL) {
s = tmp;
int len;
char s[UV__INET6_ADDRSTRLEN];
len = p - src;
if (len > UV__INET6_ADDRSTRLEN-1)
return UV_EINVAL;
memcpy(s, src, len);
s[len] = '\0';
}
return inet_pton6(s, dst);
return inet_pton6(s, dst);
} else
return inet_pton6(src, dst);
}
default:
return UV_EAFNOSUPPORT;