From bad49f6fba24e40bf8db1df9344fe0fe0262f0a1 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Tue, 11 Feb 2014 16:43:57 +0000 Subject: [PATCH] 8034182: Misc. warnings in java.net code Reviewed-by: chegar --- jdk/src/share/native/java/net/net_util.c | 19 +++++++--------- jdk/src/share/native/java/net/net_util.h | 8 +++---- .../native/java/net/Inet6AddressImpl.c | 22 +++++++++---------- .../native/java/net/NetworkInterface.c | 2 +- .../native/java/net/PlainDatagramSocketImpl.c | 2 +- .../native/java/net/Inet6AddressImpl.c | 4 ++-- .../native/java/net/NetworkInterface.c | 2 +- .../native/java/net/NetworkInterface_winXP.c | 2 +- .../net/TwoStacksPlainDatagramSocketImpl.c | 1 + .../java/net/TwoStacksPlainSocketImpl.c | 3 +-- 10 files changed, 31 insertions(+), 34 deletions(-) diff --git a/jdk/src/share/native/java/net/net_util.c b/jdk/src/share/native/java/net/net_util.c index dd93b1375bc..33acf1ce573 100644 --- a/jdk/src/share/native/java/net/net_util.c +++ b/jdk/src/share/native/java/net/net_util.c @@ -108,7 +108,7 @@ jobject getInet6Address_scopeifname(JNIEnv *env, jobject iaObj) { return (*env)->GetObjectField(env, holder, ia6_scopeifnameID); } -int setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) { +jboolean setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) { jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); (*env)->SetObjectField(env, holder, ia6_scopeifnameID, scopeifname); @@ -127,20 +127,18 @@ int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) { return (*env)->GetIntField(env, holder, ia6_scopeidID); } -int setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) { +jboolean setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) { jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); (*env)->SetIntField(env, holder, ia6_scopeidID, scopeid); if (scopeid > 0) { - (*env)->SetBooleanField(env, holder, ia6_scopeidsetID, JNI_TRUE); + (*env)->SetBooleanField(env, holder, ia6_scopeidsetID, JNI_TRUE); } return JNI_TRUE; } - -int getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) { +jboolean getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) { jobject holder, addr; - jbyteArray barr; holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID); CHECK_NULL_RETURN(holder, JNI_FALSE); @@ -150,7 +148,7 @@ int getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) { return JNI_TRUE; } -int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) { +jboolean setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) { jobject holder; jbyteArray addr; @@ -201,7 +199,6 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { jobject iaObj; #ifdef AF_INET6 if (him->sa_family == AF_INET6) { - jbyteArray ipaddress; #ifdef WIN32 struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him; #else @@ -217,11 +214,12 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { setInetAddress_family(env, iaObj, IPv4); } else { jint scope; - int ret; + jboolean ret; iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); CHECK_NULL_RETURN(iaObj, NULL); ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr)); - CHECK_NULL_RETURN(ret, NULL); + if (ret == JNI_FALSE) + return NULL; setInetAddress_family(env, iaObj, IPv6); scope = getScopeID(him); setInet6Address_scopeid(env, iaObj, scope); @@ -268,7 +266,6 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, struct sockaddr *him, jobject iaObj) return JNI_FALSE; } } else { - jbyteArray ipaddress; jbyte caddrCur[16]; int scope; diff --git a/jdk/src/share/native/java/net/net_util.h b/jdk/src/share/native/java/net/net_util.h index b77d02b2fad..9874d81db45 100644 --- a/jdk/src/share/native/java/net/net_util.h +++ b/jdk/src/share/native/java/net/net_util.h @@ -63,12 +63,12 @@ JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env); * get_ methods that return objects return NULL on error. */ extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj); -extern int setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname); +extern jboolean setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname); extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj); extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj); -extern int setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid); -extern int getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest); -extern int setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address); +extern jboolean setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid); +extern jboolean getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest); +extern jboolean setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address); extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address); extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family); diff --git a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c index 8de5a9bea1b..c5cb9e49b48 100644 --- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c @@ -66,27 +66,27 @@ */ JNIEXPORT jstring JNICALL Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { + int ret; char hostname[NI_MAXHOST+1]; hostname[0] = '\0'; - if (JVM_GetHostName(hostname, sizeof(hostname))) { + ret = JVM_GetHostName(hostname, sizeof(hostname)); + if (ret) { /* Something went wrong, maybe networking is not setup? */ strcpy(hostname, "localhost"); } else { // ensure null-terminated hostname[NI_MAXHOST] = '\0'; -#if defined(__linux__) || defined(_ALLBSD_SOURCE) - /* On Linux/FreeBSD gethostname() says "host.domain.sun.com". On - * Solaris gethostname() says "host", so extra work is needed. - */ -#else + } + +#if defined(__solaris__) && defined(AF_INET6) + if (ret == 0) { /* Solaris doesn't want to give us a fully qualified domain name. * We do a reverse lookup to try and get one. This works * if DNS occurs before NIS in /etc/resolv.conf, but fails * if NIS comes first (it still gets only a partial name). * We use thread-safe system calls. */ -#ifdef AF_INET6 struct addrinfo hints, *res; int error; @@ -111,9 +111,9 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { freeaddrinfo(res); } -#endif /* AF_INET6 */ -#endif /* __linux__ || _ALLBSD_SOURCE */ } +#endif + return (*env)->NewStringUTF(env, hostname); } @@ -402,7 +402,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } while (iterator != NULL) { - int ret1; + jboolean ret1; if (iterator->ai_family == AF_INET) { jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID); if (IS_NULL(iaObj)) { @@ -422,7 +422,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, goto cleanupAndReturn; } ret1 = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr)); - if (!ret1) { + if (ret1 == JNI_FALSE) { ret = NULL; goto cleanupAndReturn; } diff --git a/jdk/src/solaris/native/java/net/NetworkInterface.c b/jdk/src/solaris/native/java/net/NetworkInterface.c index 380dff19cc8..47e956908e8 100644 --- a/jdk/src/solaris/native/java/net/NetworkInterface.c +++ b/jdk/src/solaris/native/java/net/NetworkInterface.c @@ -677,7 +677,7 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs) { int scope=0; iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (iaObj) { - int ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr)); + jboolean ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr)); if (ret == JNI_FALSE) { return NULL; } diff --git a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c index ac4a8385e9a..6fe1683ae7d 100644 --- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c +++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c @@ -2159,7 +2159,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this, caddr[14] = ((address >> 8) & 0xff); caddr[15] = (address & 0xff); } else { - getInet6Address_ipaddress(env, iaObj, caddr); + getInet6Address_ipaddress(env, iaObj, (char*)caddr); } memcpy((void *)&(mname6.ipv6mr_multiaddr), caddr, sizeof(struct in6_addr)); diff --git a/jdk/src/windows/native/java/net/Inet6AddressImpl.c b/jdk/src/windows/native/java/net/Inet6AddressImpl.c index cac70b34dfa..356c1eac1a1 100644 --- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c @@ -221,14 +221,14 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj); inetIndex ++; } else if (iterator->ai_family == AF_INET6) { - jint scope = 0, ret1; + jint scope = 0; + jboolean ret1; jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (IS_NULL(iaObj)) { ret = NULL; goto cleanupAndReturn; } ret1 = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr)); - if (ret1 == JNI_FALSE) { ret = NULL; goto cleanupAndReturn; diff --git a/jdk/src/windows/native/java/net/NetworkInterface.c b/jdk/src/windows/native/java/net/NetworkInterface.c index 44e9a61636b..3c0ec180ee4 100644 --- a/jdk/src/windows/native/java/net/NetworkInterface.c +++ b/jdk/src/windows/native/java/net/NetworkInterface.c @@ -614,7 +614,7 @@ jobject createNetworkInterface int scope; iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (iaObj) { - int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); + jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); if (ret == JNI_FALSE) { return NULL; } diff --git a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c index 4d29e7f799d..e5580c6f3dc 100644 --- a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c +++ b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c @@ -549,7 +549,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) int scope; iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID); if (iaObj) { - int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); + jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr)); if (ret == JNI_FALSE) { return NULL; } diff --git a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c index 3f0a211fd01..2c890ecae01 100644 --- a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c +++ b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c @@ -1646,6 +1646,7 @@ static int getIndexFromIf (JNIEnv *env, jobject nif) { } static int isAdapterIpv6Enabled(JNIEnv *env, int index) { + extern int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP); netif *ifList, *curr; int ipv6Enabled = 0; if (getAllInterfacesAndAddresses (env, &ifList) < 0) { diff --git a/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c b/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c index f535073df38..0a56c85bf64 100644 --- a/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c +++ b/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c @@ -575,7 +575,6 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, { /* fields on this */ jint port; - jint scope; jint timeout = (*env)->GetIntField(env, this, psi_timeoutID); jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); @@ -750,7 +749,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, NET_SocketClose(fd); return; } - setInet6Address_ipaddress(env, socketAddressObj, (const char *)&him.him6.sin6_addr); + setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.him6.sin6_addr); setInetAddress_family(env, socketAddressObj, IPv6); setInet6Address_scopeid(env, socketAddressObj, him.him6.sin6_scope_id);