From 565dcef831cf2708a2581d326a614cf0b6bd8438 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 12 Oct 2018 18:55:17 +1300 Subject: [PATCH] Work around missing const in WSAAddressToString --- xapian-core/common/socket_utils.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/xapian-core/common/socket_utils.cc b/xapian-core/common/socket_utils.cc index aa4c1650a..15e1405c0 100644 --- a/xapian-core/common/socket_utils.cc +++ b/xapian-core/common/socket_utils.cc @@ -117,11 +117,13 @@ pretty_ip6(const void* p, char* buf) return -1; } -#ifndef __WIN32__ - // Under __WIN32__, inet_ntop()'s second parameter isn't const for some - // reason. We don't currently use inet_ntop() there, but allow for a - // non-const second parameter in case it's more widespread. + // WSAAddressToString() has a non-const first parameter. + // + // The mingw headers at least are also missing const from the corresponding + // (second) parameter of inet_ntop(), so just cast away the const in case + // this is more widespread. void* src = const_cast(p); +#ifndef __WIN32__ const char* r = inet_ntop(af, src, buf, PRETTY_IP6_LEN); if (!r) return -1; @@ -132,7 +134,7 @@ pretty_ip6(const void* p, char* buf) sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); DWORD size = PRETTY_IP6_LEN; - if (WSAAddressToString(p, in_size, NULL, buf, &size) != 0) { + if (WSAAddressToString(src, in_size, NULL, buf, &size) != 0) { return -1; } const char* r = buf; -- 2.11.4.GIT