Skip to content

Commit 82344f8

Browse files
committed
Fix MinGW Error
const auto& addr = this->At(n); auto tmp_addr = addr; the line auto tmp_addr = addr; creates a copy of the object referred to by addr. This copy, tmp_addr, is not marked as const even though addr is a constant reference. As a result, the address of tmp_addr (i.e., &tmp_addr) is of a non-const pointer type, which is acceptable for the inet_ntop function. Passing &tmp_addr to inet_ntop solves the issue of an invalid conversion from const void* to void*, because &tmp_addr is now of the type void* (or can be implicitly converted to it), bypassing the compiler error that would occur if you tried to pass directly &addr. This approach is valid provided that this->At(n) returns the data in a way that allows creating a copy with auto tmp_addr without any unintended side effects.
1 parent f606f9a commit 82344f8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clickhouse/columns/ip4.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ in_addr ColumnIPv4::operator [] (size_t n) const {
6161

6262
std::string ColumnIPv4::AsString(size_t n) const {
6363
const auto& addr = this->At(n);
64+
auto tmp_addr = addr;
6465

6566
char buf[INET_ADDRSTRLEN];
66-
const char* ip_str = inet_ntop(AF_INET, &addr, buf, INET_ADDRSTRLEN);
67+
const char* ip_str = inet_ntop(AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN);
6768

6869
if (ip_str == nullptr) {
6970
throw std::system_error(

clickhouse/columns/ip6.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ void ColumnIPv6::Clear() {
4444

4545
std::string ColumnIPv6::AsString (size_t n) const {
4646
const auto& addr = this->At(n);
47+
auto tmp_addr = addr;
4748

4849
char buf[INET6_ADDRSTRLEN];
49-
const char* ip_str = inet_ntop(AF_INET6, &addr, buf, INET6_ADDRSTRLEN);
50+
const char* ip_str = inet_ntop(AF_INET6, &tmp_addr, buf, INET6_ADDRSTRLEN);
5051

5152
if (ip_str == nullptr) {
5253
throw std::system_error(

0 commit comments

Comments
 (0)