8074817: Resolve disabled warnings for libverify
authorshade
Mon, 11 Mar 2019 12:39:51 +0100
changeset 54053 ab7c5483df44
parent 54052 a2d3ca8062b9
child 54054 1def2d745747
8074817: Resolve disabled warnings for libverify Reviewed-by: erikj, alanb
make/lib/CoreLibraries.gmk
src/java.base/share/native/libverify/check_code.c
src/java.base/share/native/libverify/check_format.c
--- a/make/lib/CoreLibraries.gmk	Mon Mar 11 11:42:57 2019 +0100
+++ b/make/lib/CoreLibraries.gmk	Mon Mar 11 12:39:51 2019 +0100
@@ -78,8 +78,6 @@
     NAME := verify, \
     OPTIMIZATION := $(LIBVERIFY_OPTIMIZATION), \
     CFLAGS := $(CFLAGS_JDKLIB), \
-    DISABLED_WARNINGS_gcc := implicit-fallthrough unused-function, \
-    DISABLED_WARNINGS_microsoft := 4244 4267, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_unix := -ljvm, \
--- a/src/java.base/share/native/libverify/check_code.c	Mon Mar 11 11:42:57 2019 +0100
+++ b/src/java.base/share/native/libverify/check_code.c	Mon Mar 11 12:39:51 2019 +0100
@@ -707,6 +707,7 @@
     return *pID;
 }
 
+#ifdef DEBUG
 static const char *
 ID_to_class_name(context_type *context, unsigned short ID)
 {
@@ -714,6 +715,7 @@
     hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
     return bucket->name;
 }
+#endif
 
 static jclass
 ID_to_class(context_type *context, unsigned short ID)
@@ -1390,7 +1392,7 @@
     case JVM_OPC_invokedynamic:
         CCerror(context,
                 "invokedynamic bytecode is not supported in this class file version");
-
+        break;
     case JVM_OPC_instanceof:
     case JVM_OPC_checkcast:
     case JVM_OPC_new:
@@ -1699,7 +1701,9 @@
             if ((index < 0) || (index > 65535)) {
                 return -1;      /* illegal */
             } else {
-                return (unsigned char *)(&lpc[index + 4]) - iptr;
+                unsigned char *finish = (unsigned char *)(&lpc[index + 4]);
+                assert(finish >= iptr);
+                return (int)(finish - iptr);
             }
         }
 
@@ -1714,8 +1718,11 @@
              */
             if (npairs < 0 || npairs >= 65536)
                 return  -1;
-            else
-                return (unsigned char *)(&lpc[2 * (npairs + 1)]) - iptr;
+            else {
+                unsigned char *finish = (unsigned char *)(&lpc[2 * (npairs + 1)]);
+                assert(finish >= iptr);
+                return (int)(finish - iptr);
+            }
         }
 
         case JVM_OPC_wide:
@@ -3828,7 +3835,8 @@
                     result = 0;
                     break;
                 }
-                length = finish - p;
+                assert(finish >= p);
+                length = (int)(finish - p);
                 if (length + 1 > (int)sizeof(buffer_space)) {
                     buffer = malloc(length + 1);
                     check_and_push(context, buffer, VM_MALLOC_BLK);
--- a/src/java.base/share/native/libverify/check_format.c	Mon Mar 11 11:42:57 2019 +0100
+++ b/src/java.base/share/native/libverify/check_format.c	Mon Mar 11 12:39:51 2019 +0100
@@ -23,6 +23,8 @@
  * questions.
  */
 
+#include <assert.h>
+#include <limits.h>
 #include <setjmp.h>
 #include <stdlib.h>
 #include <string.h>
@@ -232,7 +234,9 @@
 JNIEXPORT jboolean
 VerifyClassname(char *name, jboolean allowArrayClass)
 {
-    unsigned int length = strlen(name);
+    size_t s = strlen(name);
+    assert(s <= UINT_MAX);
+    unsigned int length = (unsigned int)s;
     char *p;
 
     if (length > 0 && name[0] == JVM_SIGNATURE_ARRAY) {