Skip to content

Commit

Permalink
Fix compiler warnings in netty Epoll and unix common
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carl-mastrangelo authored and normanmaurer committed Jun 23, 2017
1 parent 9ad74e7 commit b985615
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion transport-native-epoll/src/main/c/netty_epoll_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ static jstring netty_epoll_native_kernelVersion(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;
Expand Down
4 changes: 2 additions & 2 deletions transport-native-unix-common/src/main/c/netty_unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static jint netty_unix_socket_connectDomainSocket(JNIEnv* env, jclass clazz, jin
static jint netty_unix_socket_recvFd(JNIEnv* env, jclass clazz, jint fd) {
int socketFd;
struct msghdr descriptorMessage = { 0 };
struct iovec iov[1] = { 0 };
struct iovec iov[1] = { { 0 } };
char control[CMSG_SPACE(sizeof(int))] = { 0 };
char iovecData[1];

Expand Down Expand Up @@ -629,7 +629,7 @@ static jint netty_unix_socket_recvFd(JNIEnv* env, jclass clazz, jint fd) {

static jint netty_unix_socket_sendFd(JNIEnv* env, jclass clazz, jint socketFd, jint fd) {
struct msghdr descriptorMessage = { 0 };
struct iovec iov[1] = { 0 };
struct iovec iov[1] = { { 0 } };
char control[CMSG_SPACE(sizeof(int))] = { 0 };
char iovecData[1];

Expand Down

0 comments on commit b985615

Please sign in to comment.