From 101757e86100dca0de611e6cd5b1a8d96ded3842 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Tue, 20 Jun 2017 16:41:29 -0700 Subject: [PATCH] Fix compiler warnings in netty Epoll and unix common Motivation: Google requires stricter compilation by adding -Werror and enabling many other warnings. Modification: * fix warning caused by -Wmissing-braces * Use the address of `sendmmsg` rather than the function itself when checking for presence. This resovles the warning caused by `-Wpointer-bool-conversion`. More detail: When compiling on Linux, `sendmmsg` is always present, so the function is always nonnull. When compiling elsewhere, the function is defined as `__attribute__((weak))` which means it may be absent at link time. This is controlled by `IO_NETTY_SENDMMSG_NOT_FOUND`, which is off by default. The reason for the error is due to the risk of accidentally not calling the function. By adding `&` before the function, there is no ambiguity. (the result of the fn call cannot have its address taken.) * use != to check for sendmmsg Result: Easier compilation. --- transport-native-epoll/src/main/c/netty_epoll_native.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transport-native-epoll/src/main/c/netty_epoll_native.c b/transport-native-epoll/src/main/c/netty_epoll_native.c index 13378ac8ba..7367f0bed2 100644 --- a/transport-native-epoll/src/main/c/netty_epoll_native.c +++ b/transport-native-epoll/src/main/c/netty_epoll_native.c @@ -636,7 +636,9 @@ static jint netty_epoll_native_uioMaxIov(JNIEnv* env, jclass clazz) { } static jboolean netty_epoll_native_isSupportingSendmmsg(JNIEnv* env, jclass clazz) { - if (sendmmsg) { + // Use & to avoid warnings with -Wtautological-pointer-compare when sendmmsg is + // not weakly defined. + if (&sendmmsg != NULL) { return JNI_TRUE; } return JNI_FALSE;