8034182: Misc. warnings in java.net code

Reviewed-by: chegar
This commit is contained in:
Alan Bateman 2014-02-11 16:43:57 +00:00
parent 8acc4717a2
commit bad49f6fba
10 changed files with 31 additions and 34 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);