Unconditionally initialize sockaddrs in epoll linuxsocket (#9299)

Motivation:

Compiling with -Werror,-Wuninitialized complains about the sockaddrs being uninitialized.
I believe this is because the init function netty_unix_socket_initSockaddr is in a
separate compilation unit.  Since this code isn't on the criticial path, it's easy
to just memset the variables rather than suppress the warning.

Modification:
Always clear the sockaddrs, even if they will be initialized later.

Result:
Able to compile with warnings turned on
This commit is contained in:
Carl Mastrangelo 2019-06-29 03:16:59 -07:00 committed by Norman Maurer
parent 05c2967e4a
commit 262ced7ce4
1 changed files with 19 additions and 0 deletions

View File

@ -83,6 +83,8 @@ static void netty_epoll_linuxsocket_setInterface(JNIEnv* env, jclass clazz, jint
socklen_t interfaceAddrSize;
struct sockaddr_in* interfaceIpAddr;
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
if (ipv6 == JNI_TRUE) {
if (interfaceIndex == -1) {
netty_unix_errors_throwIOException(env, "Unable to find network index");
@ -168,6 +170,9 @@ static void netty_epoll_linuxsocket_joinGroup(JNIEnv* env, jclass clazz, jint fd
struct sockaddr_in6* groupIp6Addr;
struct ipv6_mreq mreq6;
memset(&groupAddr, 0, sizeof(groupAddr));
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
return;
@ -218,6 +223,10 @@ static void netty_epoll_linuxsocket_joinSsmGroup(JNIEnv* env, jclass clazz, jint
struct group_source_req mreq6;
memset(&groupAddr, 0, sizeof(groupAddr));
memset(&sourceAddr, 0, sizeof(sourceAddr));
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
return;
@ -271,6 +280,9 @@ static void netty_epoll_linuxsocket_leaveGroup(JNIEnv* env, jclass clazz, jint f
struct sockaddr_in6* groupIp6Addr;
struct ipv6_mreq mreq6;
memset(&groupAddr, 0, sizeof(groupAddr));
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
return;
@ -320,6 +332,10 @@ static void netty_epoll_linuxsocket_leaveSsmGroup(JNIEnv* env, jclass clazz, jin
struct ip_mreq_source mreq;
struct group_source_req mreq6;
memset(&groupAddr, 0, sizeof(groupAddr));
memset(&sourceAddr, 0, sizeof(sourceAddr));
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
@ -366,6 +382,9 @@ static void netty_epoll_linuxsocket_leaveSsmGroup(JNIEnv* env, jclass clazz, jin
static void netty_epoll_linuxsocket_setTcpMd5Sig(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jbyteArray address, jint scopeId, jbyteArray key) {
struct sockaddr_storage addr;
socklen_t addrSize;
memset(&addr, 0, sizeof(addr));
if (netty_unix_socket_initSockaddr(env, ipv6, address, scopeId, 0, &addr, &addrSize) == -1) {
netty_unix_errors_throwIOException(env, "Could not init sockaddr");
return;