From: Roger Meier Date: Tue, 8 Jul 2014 05:29:12 +0000 (+0200) Subject: THRIFT-2605 TSocket warning on gcc 4.8.3 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=3e50a9a1d01950f356242aaab0cbf5fae778b81c;p=common%2Fthrift.git THRIFT-2605 TSocket warning on gcc 4.8.3 Patch: Konrad Grochowski --- diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp index b686c6ca..e7d3ec69 100755 --- a/lib/cpp/src/thrift/transport/TServerSocket.cpp +++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp @@ -310,15 +310,14 @@ void TServerSocket::listen() { #ifndef _WIN32 // Unix Domain Socket - struct sockaddr_un address = {0}; - size_t len = path_.size()+1; - - if (len > sizeof(address.sun_path)) { + size_t len = path_.size() + 1; + if (len > sizeof(sockaddr_un::sun_path)) { int errno_copy = THRIFT_GET_SOCKET_ERROR; GlobalOutput.perror("TSocket::listen() Unix Domain socket path too long", errno_copy); throw TTransportException(TTransportException::NOT_OPEN, " Unix Domain socket path too long"); } + struct sockaddr_un address; address.sun_family = AF_UNIX; memcpy(address.sun_path, path_.c_str(), len); socklen_t structlen = static_cast(sizeof(address)); diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp b/lib/cpp/src/thrift/transport/TSocket.cpp index 8595506f..7dec4420 100755 --- a/lib/cpp/src/thrift/transport/TSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSocket.cpp @@ -253,15 +253,14 @@ void TSocket::openConnection(struct addrinfo *res) { #ifndef _WIN32 - struct sockaddr_un address = {0}; - size_t len = path_.size()+1; - - if (len > sizeof(address.sun_path)) { + size_t len = path_.size() + 1; + if (len > sizeof(sockaddr_un::sun_path)) { int errno_copy = THRIFT_GET_SOCKET_ERROR; GlobalOutput.perror("TSocket::open() Unix Domain socket path too long", errno_copy); throw TTransportException(TTransportException::NOT_OPEN, " Unix Domain socket path too long"); } + struct sockaddr_un address; address.sun_family = AF_UNIX; memcpy(address.sun_path, path_.c_str(), len); socklen_t structlen = static_cast(sizeof(address)); @@ -378,13 +377,13 @@ void TSocket::local_open(){ error = getaddrinfo(host_.c_str(), port, &hints, &res0); -#ifdef _WIN32 - if (error == WSANO_DATA) { - hints.ai_flags &= ~AI_ADDRCONFIG; - error = getaddrinfo(host_.c_str(), port, &hints, &res0); - } -#endif - +#ifdef _WIN32 + if (error == WSANO_DATA) { + hints.ai_flags &= ~AI_ADDRCONFIG; + error = getaddrinfo(host_.c_str(), port, &hints, &res0); + } +#endif + if (error) { string errStr = "TSocket::open() getaddrinfo() " + getSocketInfo() + string(THRIFT_GAI_STRERROR(error)); GlobalOutput(errStr.c_str());