6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
authoralanb
Thu, 07 Oct 2010 14:36:17 +0100
changeset 6850 56966b0a6a0d
parent 6849 02dc13de9152
child 6851 415649ab5519
child 6852 c4afb73bfc6b
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code Reviewed-by: andrew, mchung, ohair
jdk/src/share/native/common/jdk_util.c
jdk/src/share/native/common/jni_util.c
jdk/src/share/native/java/lang/Class.c
jdk/src/share/native/java/lang/ClassLoader.c
jdk/src/share/native/java/lang/System.c
jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
jdk/src/share/native/java/lang/reflect/Proxy.c
jdk/src/share/native/java/nio/Bits.c
jdk/src/share/native/sun/management/Flag.c
jdk/src/share/native/sun/misc/VM.c
jdk/src/share/native/sun/misc/VMSupport.c
jdk/src/solaris/native/java/io/UnixFileSystem_md.c
jdk/src/solaris/native/java/io/canonicalize_md.c
jdk/src/solaris/native/java/lang/java_props_md.c
jdk/src/solaris/native/sun/net/sdp/SdpSupport.c
jdk/src/solaris/native/sun/nio/ch/Net.c
jdk/src/solaris/native/sun/nio/ch/SctpNet.c
jdk/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c
jdk/src/windows/native/common/jni_util_md.c
jdk/src/windows/native/java/lang/java_props_md.c
jdk/src/windows/native/java/util/TimeZone_md.c
jdk/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c
jdk/src/windows/native/sun/nio/ch/WindowsSelectorImpl.c
--- a/jdk/src/share/native/common/jdk_util.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/common/jdk_util.c	Thu Oct 07 14:36:17 2010 +0100
@@ -76,7 +76,7 @@
     }
 
 
-    memset(info, 0, sizeof(info_size));
+    memset(info, 0, info_size);
     info->jdk_version = ((jdk_major_version & 0xFF) << 24) |
                         ((jdk_minor_version & 0xFF) << 16) |
                         ((jdk_micro_version & 0xFF) << 8)  |
--- a/jdk/src/share/native/common/jni_util.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/common/jni_util.c	Thu Oct 07 14:36:17 2010 +0100
@@ -433,7 +433,7 @@
     for (i=0; i<len; i++) {
         jchar unicode = str[i];
         if (unicode <= 0x00ff)
-            result[i] = unicode;
+            result[i] = (char)unicode;
         else
             result[i] = '?';
     }
@@ -498,7 +498,7 @@
     for (i=0; i<len; i++) {
         jchar unicode = str[i];
         if (unicode <= 0x007f )
-            result[i] = unicode;
+            result[i] = (char)unicode;
         else
             result[i] = '?';
     }
@@ -569,7 +569,7 @@
     for (i=0; i<len; i++) {
         jchar c = str[i];
         if (c < 256)
-            result[i] = c;
+            result[i] = (char)c;
         else switch(c) {
             case 0x20AC: result[i] = (char)0x80; break;
             case 0x201A: result[i] = (char)0x82; break;
--- a/jdk/src/share/native/java/lang/Class.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/lang/Class.c	Thu Oct 07 14:36:17 2010 +0100
@@ -102,8 +102,8 @@
     char *clname;
     jclass cls = 0;
     char buf[128];
-    int len;
-    int unicode_len;
+    jsize len;
+    jsize unicode_len;
 
     if (classname == NULL) {
         JNU_ThrowNullPointerException(env, 0);
@@ -112,7 +112,7 @@
 
     len = (*env)->GetStringUTFLength(env, classname);
     unicode_len = (*env)->GetStringLength(env, classname);
-    if (len >= sizeof(buf)) {
+    if (len >= (jsize)sizeof(buf)) {
         clname = malloc(len + 1);
         if (clname == NULL) {
             JNU_ThrowOutOfMemoryError(env, NULL);
--- a/jdk/src/share/native/java/lang/ClassLoader.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/lang/ClassLoader.c	Thu Oct 07 14:36:17 2010 +0100
@@ -331,7 +331,7 @@
     if (handle) {
         const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
         JNI_OnLoad_t JNI_OnLoad;
-        int i;
+        unsigned int i;
         for (i = 0; i < sizeof(onLoadSymbols) / sizeof(char *); i++) {
             JNI_OnLoad = (JNI_OnLoad_t)
                 JVM_FindLibraryEntry(handle, onLoadSymbols[i]);
@@ -369,7 +369,7 @@
         cause = (*env)->ExceptionOccurred(env);
         if (cause) {
             (*env)->ExceptionClear(env);
-            (*env)->SetLongField(env, this, handleID, (jlong)NULL);
+            (*env)->SetLongField(env, this, handleID, (jlong)0);
             (*env)->Throw(env, cause);
         }
         goto done;
@@ -392,7 +392,7 @@
     const char *onUnloadSymbols[] = JNI_ONUNLOAD_SYMBOLS;
     void *handle;
     JNI_OnUnload_t JNI_OnUnload;
-    int i;
+    unsigned int i;
 
     if (!initIDs(env))
         return;
--- a/jdk/src/share/native/java/lang/System.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/lang/System.c	Thu Oct 07 14:36:17 2010 +0100
@@ -109,7 +109,7 @@
   #error "ERROR: No override of JAVA_SPECIFICATION_VENDOR is allowed"
 #else
   #define JAVA_SPECIFICATION_VENDOR "Oracle Corporation"
-#endif
+#endif
 
 static int fmtdefault; // boolean value
 jobject fillI18nProps(JNIEnv *env, jobject props, char *baseKey,
--- a/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h	Thu Oct 07 14:36:17 2010 +0100
@@ -46,11 +46,13 @@
 #define __LOp(x) *(1+(int*)x)
 #endif
 
+#ifndef __P
 #ifdef __STDC__
 #define __P(p)  p
 #else
 #define __P(p)  ()
 #endif
+#endif
 
 /*
  * ANSI/POSIX
--- a/jdk/src/share/native/java/lang/reflect/Proxy.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/lang/reflect/Proxy.c	Thu Oct 07 14:36:17 2010 +0100
@@ -82,9 +82,9 @@
         goto free_body;
 
     if (name != NULL) {
-        int len = (*env)->GetStringUTFLength(env, name);
-        int unicode_len = (*env)->GetStringLength(env, name);
-        if (len >= sizeof(buf)) {
+        jsize len = (*env)->GetStringUTFLength(env, name);
+        jsize unicode_len = (*env)->GetStringLength(env, name);
+        if (len >= (jsize)sizeof(buf)) {
             utfName = malloc(len + 1);
             if (utfName == NULL) {
                 JNU_ThrowOutOfMemoryError(env, NULL);
--- a/jdk/src/share/native/java/nio/Bits.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/java/nio/Bits.c	Thu Oct 07 14:36:17 2010 +0100
@@ -72,7 +72,7 @@
                                       jlong srcPos, jlong dstAddr, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jshort *srcShort, *dstShort, *endShort;
     jshort tmpShort;
 
@@ -83,7 +83,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, src);
 
@@ -107,7 +107,7 @@
                                     jobject dst, jlong dstPos, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jshort *srcShort, *dstShort, *endShort;
     jshort tmpShort;
 
@@ -118,7 +118,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, dst);
 
@@ -142,7 +142,7 @@
                                     jlong srcPos, jlong dstAddr, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jint *srcInt, *dstInt, *endInt;
     jint tmpInt;
 
@@ -153,7 +153,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, src);
 
@@ -177,7 +177,7 @@
                                   jobject dst, jlong dstPos, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jint *srcInt, *dstInt, *endInt;
     jint tmpInt;
 
@@ -188,7 +188,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, dst);
 
@@ -212,7 +212,7 @@
                                      jlong srcPos, jlong dstAddr, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jlong *srcLong, *dstLong, *endLong;
     jlong tmpLong;
 
@@ -223,7 +223,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, src);
 
@@ -247,7 +247,7 @@
                                    jobject dst, jlong dstPos, jlong length)
 {
     jbyte *bytes;
-    size_t i, size;
+    size_t size;
     jlong *srcLong, *dstLong, *endLong;
     jlong tmpLong;
 
@@ -258,7 +258,7 @@
         if (length > MBYTE)
             size = MBYTE;
         else
-            size = length;
+            size = (size_t)length;
 
         GETCRITICAL(bytes, env, dst);
 
--- a/jdk/src/share/native/sun/management/Flag.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/sun/management/Flag.c	Thu Oct 07 14:36:17 2010 +0100
@@ -25,6 +25,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <jni.h>
 #include "management.h"
 #include "sun_management_Flag.h"
@@ -80,8 +81,6 @@
 Java_sun_management_Flag_getFlags
   (JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count)
 {
-    char errmsg[128];
-
     jint num_flags, i, index;
     jmmVMGlobal* globals;
     size_t gsize;
--- a/jdk/src/share/native/sun/misc/VM.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/sun/misc/VM.c	Thu Oct 07 14:36:17 2010 +0100
@@ -23,6 +23,8 @@
  * questions.
  */
 
+#include <string.h>
+
 #include "jni.h"
 #include "jni_util.h"
 #include "jlong.h"
@@ -113,7 +115,6 @@
 
 JNIEXPORT void JNICALL
 Java_sun_misc_VM_initialize(JNIEnv *env, jclass cls) {
-    char errmsg[128];
     GetJvmVersionInfo_fp func_p;
 
     if (!JDK_InitJvmHandle()) {
@@ -123,8 +124,6 @@
 
     func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
      if (func_p != NULL) {
-        char errmsg[100];
-        jfieldID fid;
         jvm_version_info info;
 
         memset(&info, 0, sizeof(info));
--- a/jdk/src/share/native/sun/misc/VMSupport.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/share/native/sun/misc/VMSupport.c	Thu Oct 07 14:36:17 2010 +0100
@@ -38,8 +38,6 @@
 JNIEXPORT jobject JNICALL
 Java_sun_misc_VMSupport_initAgentProperties(JNIEnv *env, jclass cls, jobject props)
 {
-    char errmsg[128];
-
     if (InitAgentProperties_fp == NULL) {
         if (!JDK_InitJvmHandle()) {
             JNU_ThrowInternalError(env,
--- a/jdk/src/solaris/native/java/io/UnixFileSystem_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/java/io/UnixFileSystem_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -119,7 +119,7 @@
                                         jobject file, jint a)
 {
     jboolean rv = JNI_FALSE;
-    int mode;
+    int mode = 0;
     switch (a) {
     case java_io_FileSystem_ACCESS_READ:
         mode = R_OK;
@@ -151,7 +151,8 @@
     jboolean rv = JNI_FALSE;
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
-        int amode, mode;
+        int amode = 0;
+        int mode;
         switch (access) {
         case java_io_FileSystem_ACCESS_READ:
             if (owneronly)
--- a/jdk/src/solaris/native/java/io/canonicalize_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/java/io/canonicalize_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -246,7 +246,7 @@
         if (r != NULL) {
             /* Append unresolved subpath to resolved subpath */
             int rn = strlen(r);
-            if (rn + strlen(p) >= len) {
+            if (rn + (int)strlen(p) >= len) {
                 /* Buffer overflow */
                 errno = ENAMETOOLONG;
                 return -1;
--- a/jdk/src/solaris/native/java/lang/java_props_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/java/lang/java_props_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -46,7 +46,9 @@
 #include "java_props.h"
 
 #ifdef __linux__
-#define CODESET _NL_CTYPE_CODESET_NAME
+  #ifndef CODESET
+  #define CODESET _NL_CTYPE_CODESET_NAME
+  #endif
 #else
 #ifdef ALT_CODESET_KEY
 #define CODESET ALT_CODESET_KEY
@@ -289,7 +291,7 @@
 java_props_t *
 GetJavaProperties(JNIEnv *env)
 {
-    static java_props_t sprops = {0};
+    static java_props_t sprops;
     char *v; /* tmp var */
 
     if (sprops.user_dir) {
--- a/jdk/src/solaris/native/sun/net/sdp/SdpSupport.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/sun/net/sdp/SdpSupport.c	Thu Oct 07 14:36:17 2010 +0100
@@ -68,7 +68,7 @@
      */
     if (ipv6_available()) {
         JNU_ThrowIOException(env, "IPv6 not supported");
-        return;
+        return -1;
     }
     s = socket(AF_INET_SDP, SOCK_STREAM, 0);
 #else
--- a/jdk/src/solaris/native/sun/nio/ch/Net.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/sun/nio/ch/Net.c	Thu Oct 07 14:36:17 2010 +0100
@@ -298,7 +298,8 @@
     struct linger linger;
     u_char carg;
     void *arg;
-    int arglen, n;
+    socklen_t arglen;
+    int n;
 
     /* Option value is an int except for a few specific cases */
 
@@ -317,7 +318,7 @@
     }
 
     if (mayNeedConversion) {
-        n = NET_GetSockOpt(fdval(env, fdo), level, opt, arg, &arglen);
+        n = NET_GetSockOpt(fdval(env, fdo), level, opt, arg, (int*)&arglen);
     } else {
         n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen);
     }
@@ -527,7 +528,7 @@
 Java_sun_nio_ch_Net_getInterface4(JNIEnv* env, jobject this, jobject fdo)
 {
     struct in_addr in;
-    int arglen = sizeof(struct in_addr);
+    socklen_t arglen = sizeof(struct in_addr);
     int n;
 
     n = getsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, (void*)&in, &arglen);
@@ -556,7 +557,7 @@
 Java_sun_nio_ch_Net_getInterface6(JNIEnv* env, jobject this, jobject fdo)
 {
     int index;
-    int arglen = sizeof(index);
+    socklen_t arglen = sizeof(index);
     int n;
 
     n = getsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)&index, &arglen);
--- a/jdk/src/solaris/native/sun/nio/ch/SctpNet.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/sun/nio/ch/SctpNet.c	Thu Oct 07 14:36:17 2010 +0100
@@ -537,7 +537,7 @@
     int result;
     struct linger linger;
     void *arg;
-    unsigned int arglen;
+    int arglen;
 
     if (mapSocketOption(opt, &klevel, &kopt) < 0) {
         JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
--- a/jdk/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/solaris/native/sun/nio/ch/UnixAsynchronousSocketChannelImpl.c	Thu Oct 07 14:36:17 2010 +0100
@@ -40,10 +40,10 @@
     jobject this, int fd)
 {
     int error = 0;
-    int n = sizeof(error);
+    socklen_t arglen = sizeof(error);
     int result;
 
-    result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n);
+    result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &arglen);
     if (result < 0) {
         JNU_ThrowIOExceptionWithLastError(env, "getsockopt");
     } else {
--- a/jdk/src/windows/native/common/jni_util_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/windows/native/common/jni_util_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -79,7 +79,7 @@
 }
 
 jstring nativeNewStringPlatform(JNIEnv *env, const char *str) {
-    static String_char_constructor = NULL;
+    static jmethodID String_char_constructor;
     if (useNativeConverter(env)) {
         // use native Unicode conversion so Kernel isn't required during
         // System.initProperties
--- a/jdk/src/windows/native/java/lang/java_props_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/windows/native/java/lang/java_props_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -489,7 +489,7 @@
             break;
         }
         sprintf(buf, "%d.%d", ver.dwMajorVersion, ver.dwMinorVersion);
-        sprops.os_version = strdup(buf);
+        sprops.os_version = _strdup(buf);
 #if _M_IA64
         sprops.os_arch = "ia64";
 #elif _M_AMD64
@@ -500,7 +500,7 @@
         sprops.os_arch = "unknown";
 #endif
 
-        sprops.patch_level = strdup(ver.szCSDVersion);
+        sprops.patch_level = _strdup(ver.szCSDVersion);
 
         sprops.desktop = "windows";
     }
--- a/jdk/src/windows/native/java/util/TimeZone_md.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/windows/native/java/util/TimeZone_md.c	Thu Oct 07 14:36:17 2010 +0100
@@ -26,6 +26,7 @@
 #include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "jvm.h"
 #include "TimeZone_md.h"
 
 #define VALUE_UNKNOWN           0
@@ -463,7 +464,7 @@
                 /*
                  * Found the time zone in the mapping table.
                  */
-                javaTZName = strdup(items[TZ_JAVA_NAME]);
+                javaTZName = _strdup(items[TZ_JAVA_NAME]);
                 break;
             }
             /*
@@ -473,7 +474,7 @@
                 strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
             } else if (country != NULL && strcmp(items[TZ_REGION], country) == 0) {
                 if (value_type == VALUE_MAPID) {
-                    javaTZName = strdup(items[TZ_JAVA_NAME]);
+                    javaTZName = _strdup(items[TZ_JAVA_NAME]);
                     break;
                 }
                 strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
@@ -490,7 +491,7 @@
     fclose(fp);
 
     if (javaTZName == NULL && bestMatch[0] != '\0') {
-        javaTZName = strdup(bestMatch);
+        javaTZName = _strdup(bestMatch);
     }
     return javaTZName;
 
@@ -515,7 +516,7 @@
 
     if (result != VALUE_UNKNOWN) {
         if (result == VALUE_GMTOFFSET) {
-            std_timezone = strdup(winZoneName);
+            std_timezone = _strdup(winZoneName);
         } else {
             std_timezone = matchJavaTZ(java_home_dir, result,
                                        winZoneName, winMapID, country);
--- a/jdk/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/windows/native/sun/nio/ch/ServerSocketChannelImpl.c	Thu Oct 07 14:36:17 2010 +0100
@@ -84,7 +84,6 @@
     jobject remote_ia;
     int remote_port;
     jobject isa;
-    jobject ia;
     int addrlen = sizeof(sa);
 
     memset((char *)&sa, 0, sizeof(sa));
--- a/jdk/src/windows/native/sun/nio/ch/WindowsSelectorImpl.c	Thu Oct 07 10:35:36 2010 +0100
+++ b/jdk/src/windows/native/sun/nio/ch/WindowsSelectorImpl.c	Thu Oct 07 14:36:17 2010 +0100
@@ -223,7 +223,7 @@
     jboolean discarded = JNI_FALSE;
     int n;
     do {
-        n = recv(s, &data, sizeof(data), MSG_OOB);
+        n = recv(s, (char*)&data, sizeof(data), MSG_OOB);
         if (n > 0) {
             discarded = JNI_TRUE;
         }