Skip to content

Commit 262ced7

Browse files
carl-mastrangelonormanmaurer
authored andcommitted
Unconditionally initialize sockaddrs in epoll linuxsocket (netty#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
1 parent 05c2967 commit 262ced7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

transport-native-epoll/src/main/c/netty_epoll_linuxsocket.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static void netty_epoll_linuxsocket_setInterface(JNIEnv* env, jclass clazz, jint
8383
socklen_t interfaceAddrSize;
8484
struct sockaddr_in* interfaceIpAddr;
8585

86+
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
87+
8688
if (ipv6 == JNI_TRUE) {
8789
if (interfaceIndex == -1) {
8890
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
168170
struct sockaddr_in6* groupIp6Addr;
169171
struct ipv6_mreq mreq6;
170172

173+
memset(&groupAddr, 0, sizeof(groupAddr));
174+
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
175+
171176
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
172177
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
173178
return;
@@ -218,6 +223,10 @@ static void netty_epoll_linuxsocket_joinSsmGroup(JNIEnv* env, jclass clazz, jint
218223

219224
struct group_source_req mreq6;
220225

226+
memset(&groupAddr, 0, sizeof(groupAddr));
227+
memset(&sourceAddr, 0, sizeof(sourceAddr));
228+
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
229+
221230
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
222231
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
223232
return;
@@ -271,6 +280,9 @@ static void netty_epoll_linuxsocket_leaveGroup(JNIEnv* env, jclass clazz, jint f
271280
struct sockaddr_in6* groupIp6Addr;
272281
struct ipv6_mreq mreq6;
273282

283+
memset(&groupAddr, 0, sizeof(groupAddr));
284+
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
285+
274286
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
275287
netty_unix_errors_throwIOException(env, "Could not init sockaddr for groupAddress");
276288
return;
@@ -320,6 +332,10 @@ static void netty_epoll_linuxsocket_leaveSsmGroup(JNIEnv* env, jclass clazz, jin
320332
struct ip_mreq_source mreq;
321333
struct group_source_req mreq6;
322334

335+
memset(&groupAddr, 0, sizeof(groupAddr));
336+
memset(&sourceAddr, 0, sizeof(sourceAddr));
337+
memset(&interfaceAddr, 0, sizeof(interfaceAddr));
338+
323339

324340
if (netty_unix_socket_initSockaddr(env, ipv6, groupAddress, scopeId, 0, &groupAddr, &groupAddrSize) == -1) {
325341
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
366382
static void netty_epoll_linuxsocket_setTcpMd5Sig(JNIEnv* env, jclass clazz, jint fd, jboolean ipv6, jbyteArray address, jint scopeId, jbyteArray key) {
367383
struct sockaddr_storage addr;
368384
socklen_t addrSize;
385+
386+
memset(&addr, 0, sizeof(addr));
387+
369388
if (netty_unix_socket_initSockaddr(env, ipv6, address, scopeId, 0, &addr, &addrSize) == -1) {
370389
netty_unix_errors_throwIOException(env, "Could not init sockaddr");
371390
return;

0 commit comments

Comments
 (0)