Blame pr2462-resolve_disabled_warnings_for_libunpack_and_the_unpack200_binary.patch

74b02f5
# HG changeset patch
74b02f5
# User mikael
74b02f5
# Date 1426870964 25200
74b02f5
#      Fri Mar 20 10:02:44 2015 -0700
74b02f5
# Node ID ee13ce369705a700b867f8c77423580b7b22cc13
74b02f5
# Parent  7847ccfb240b35ed0dd328f0404b713b20e0905a
74b02f5
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
74b02f5
Reviewed-by: dholmes, ksrini
74b02f5
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/bytes.h openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/bytes.h
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/bytes.h
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/bytes.h
74b02f5
@@ -63,7 +63,7 @@
74b02f5
     bytes res;
74b02f5
     res.ptr = ptr + beg;
74b02f5
     res.len = end - beg;
74b02f5
-    assert(res.len == 0 || inBounds(res.ptr) && inBounds(res.limit()-1));
74b02f5
+    assert(res.len == 0 || (inBounds(res.ptr) && inBounds(res.limit()-1)));
74b02f5
     return res;
74b02f5
   }
74b02f5
   // building C strings inside byte buffers:
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp
74b02f5
@@ -292,7 +292,7 @@
74b02f5
 
74b02f5
   if (uPtr->aborting()) {
74b02f5
     THROW_IOE(uPtr->get_abort_message());
74b02f5
-    return false;
74b02f5
+    return null;
74b02f5
   }
74b02f5
 
74b02f5
   // We have fetched all the files.
74b02f5
@@ -310,7 +310,7 @@
74b02f5
 JNIEXPORT jlong JNICALL
74b02f5
 Java_com_sun_java_util_jar_pack_NativeUnpack_finish(JNIEnv *env, jobject pObj) {
74b02f5
   unpacker* uPtr = get_unpacker(env, pObj, false);
74b02f5
-  CHECK_EXCEPTION_RETURN_VALUE(uPtr, NULL);
74b02f5
+  CHECK_EXCEPTION_RETURN_VALUE(uPtr, 0);
74b02f5
   size_t consumed = uPtr->input_consumed();
74b02f5
   free_unpacker(env, pObj, uPtr);
74b02f5
   return consumed;
74b02f5
@@ -320,6 +320,7 @@
74b02f5
 Java_com_sun_java_util_jar_pack_NativeUnpack_setOption(JNIEnv *env, jobject pObj,
74b02f5
                                        jstring pProp, jstring pValue) {
74b02f5
   unpacker*   uPtr  = get_unpacker(env, pObj);
74b02f5
+  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
74b02f5
   const char* prop  = env->GetStringUTFChars(pProp, JNI_FALSE);
74b02f5
   CHECK_EXCEPTION_RETURN_VALUE(prop, false);
74b02f5
   const char* value = env->GetStringUTFChars(pValue, JNI_FALSE);
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
74b02f5
@@ -142,31 +142,28 @@
74b02f5
   return progname;
74b02f5
 }
74b02f5
 
74b02f5
-static const char* usage_lines[] = {
74b02f5
-  "Usage:  %s [-opt... | --option=value]... x.pack[.gz] y.jar\n",
74b02f5
-    "\n",
74b02f5
-    "Unpacking Options\n",
74b02f5
-    "  -H{h}, --deflate-hint={h}     override transmitted deflate hint: true, false, or keep (default)\n",
74b02f5
-    "  -r, --remove-pack-file        remove input file after unpacking\n",
74b02f5
-    "  -v, --verbose                 increase program verbosity\n",
74b02f5
-    "  -q, --quiet                   set verbosity to lowest level\n",
74b02f5
-    "  -l{F}, --log-file={F}         output to the given log file, or '-' for standard output (default)\n",
74b02f5
-    "  -?, -h, --help                print this message\n",
74b02f5
-    "  -V, --version                 print program version\n",
74b02f5
-    "  -J{X}                         Java VM argument (ignored)\n",
74b02f5
-    null
74b02f5
-};
74b02f5
+#define USAGE_HEADER "Usage:  %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
74b02f5
+#define USAGE_OPTIONS \
74b02f5
+    "\n" \
74b02f5
+    "Unpacking Options\n" \
74b02f5
+    "  -H{h}, --deflate-hint={h}     override transmitted deflate hint: true, false, or keep (default)\n" \
74b02f5
+    "  -r, --remove-pack-file        remove input file after unpacking\n" \
74b02f5
+    "  -v, --verbose                 increase program verbosity\n" \
74b02f5
+    "  -q, --quiet                   set verbosity to lowest level\n" \
74b02f5
+    "  -l{F}, --log-file={F}         output to the given log file, or '-' for standard output (default)\n" \
74b02f5
+    "  -?, -h, --help                print this message\n" \
74b02f5
+    "  -V, --version                 print program version\n" \
74b02f5
+    "  -J{X}                         Java VM argument (ignored)\n"
74b02f5
 
74b02f5
 static void usage(unpacker* u, const char* progname, bool full = false) {
74b02f5
   // WinMain does not set argv[0] to the progrname
74b02f5
   progname = (progname != null) ? nbasename(progname) : "unpack200";
74b02f5
-  for (int i = 0; usage_lines[i] != null; i++) {
74b02f5
-    fprintf(u->errstrm, usage_lines[i], progname);
74b02f5
-    if (!full) {
74b02f5
-      fprintf(u->errstrm,
74b02f5
-              "(For more information, run %s --help .)\n", progname);
74b02f5
-      break;
74b02f5
-    }
74b02f5
+
74b02f5
+  fprintf(u->errstrm, USAGE_HEADER, progname);
74b02f5
+  if (full) {
74b02f5
+    fprintf(u->errstrm, USAGE_OPTIONS);
74b02f5
+  } else {
74b02f5
+    fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
74b02f5
   }
74b02f5
 }
74b02f5
 
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
74b02f5
@@ -222,9 +222,9 @@
74b02f5
   }
74b02f5
 
74b02f5
 #ifdef PRODUCT
74b02f5
-  char* string() { return 0; }
74b02f5
+  const char* string() { return NULL; }
74b02f5
 #else
74b02f5
-  char* string();  // see far below
74b02f5
+  const char* string();  // see far below
74b02f5
 #endif
74b02f5
 };
74b02f5
 
74b02f5
@@ -715,13 +715,13 @@
74b02f5
   // Now we can size the whole archive.
74b02f5
   // Read everything else into a mega-buffer.
74b02f5
   rp = hdr.rp;
74b02f5
-  int header_size_0 = (int)(rp - input.base()); // used-up header (4byte + 3int)
74b02f5
-  int header_size_1 = (int)(rplimit - rp);      // buffered unused initial fragment
74b02f5
-  int header_size   = header_size_0+header_size_1;
74b02f5
+  size_t header_size_0 = (rp - input.base()); // used-up header (4byte + 3int)
74b02f5
+  size_t header_size_1 = (rplimit - rp);      // buffered unused initial fragment
74b02f5
+  size_t header_size   = header_size_0 + header_size_1;
74b02f5
   unsized_bytes_read = header_size_0;
74b02f5
   CHECK;
74b02f5
   if (foreign_buf) {
74b02f5
-    if (archive_size > (size_t)header_size_1) {
74b02f5
+    if (archive_size > header_size_1) {
74b02f5
       abort("EOF reading fixed input buffer");
74b02f5
       return;
74b02f5
     }
74b02f5
@@ -735,7 +735,7 @@
74b02f5
       return;
74b02f5
     }
74b02f5
     input.set(U_NEW(byte, add_size(header_size_0, archive_size, C_SLOP)),
74b02f5
-              (size_t) header_size_0 + archive_size);
74b02f5
+              header_size_0 + archive_size);
74b02f5
     CHECK;
74b02f5
     assert(input.limit()[0] == 0);
74b02f5
     // Move all the bytes we read initially into the real buffer.
74b02f5
@@ -958,13 +958,13 @@
74b02f5
   nentries = next_entry;
74b02f5
 
74b02f5
   // place a limit on future CP growth:
74b02f5
-  int generous = 0;
74b02f5
+  size_t generous = 0;
74b02f5
   generous = add_size(generous, u->ic_count); // implicit name
74b02f5
   generous = add_size(generous, u->ic_count); // outer
74b02f5
   generous = add_size(generous, u->ic_count); // outer.utf8
74b02f5
   generous = add_size(generous, 40); // WKUs, misc
74b02f5
   generous = add_size(generous, u->class_count); // implicit SourceFile strings
74b02f5
-  maxentries = add_size(nentries, generous);
74b02f5
+  maxentries = (uint)add_size(nentries, generous);
74b02f5
 
74b02f5
   // Note that this CP does not include "empty" entries
74b02f5
   // for longs and doubles.  Those are introduced when
74b02f5
@@ -982,8 +982,9 @@
74b02f5
   }
74b02f5
 
74b02f5
   // Initialize *all* our entries once
74b02f5
-  for (int i = 0 ; i < maxentries ; i++)
74b02f5
+  for (uint i = 0 ; i < maxentries ; i++) {
74b02f5
     entries[i].outputIndex = REQUESTED_NONE;
74b02f5
+  }
74b02f5
 
74b02f5
   initGroupIndexes();
74b02f5
   // Initialize hashTab to a generous power-of-two size.
74b02f5
@@ -3677,21 +3678,22 @@
74b02f5
 
74b02f5
 unpacker* debug_u;
74b02f5
 
74b02f5
-static bytes& getbuf(int len) {  // for debugging only!
74b02f5
+static bytes& getbuf(size_t len) {  // for debugging only!
74b02f5
   static int bn = 0;
74b02f5
   static bytes bufs[8];
74b02f5
   bytes& buf = bufs[bn++ & 7];
74b02f5
-  while ((int)buf.len < len+10)
74b02f5
+  while (buf.len < len + 10) {
74b02f5
     buf.realloc(buf.len ? buf.len * 2 : 1000);
74b02f5
+  }
74b02f5
   buf.ptr[0] = 0;  // for the sake of strcat
74b02f5
   return buf;
74b02f5
 }
74b02f5
 
74b02f5
-char* entry::string() {
74b02f5
+const char* entry::string() {
74b02f5
   bytes buf;
74b02f5
   switch (tag) {
74b02f5
   case CONSTANT_None:
74b02f5
-    return (char*)"<empty>";
74b02f5
+    return "<empty>";
74b02f5
   case CONSTANT_Signature:
74b02f5
     if (value.b.ptr == null)
74b02f5
       return ref(0)->string();
74b02f5
@@ -3711,26 +3713,28 @@
74b02f5
     break;
74b02f5
   default:
74b02f5
     if (nrefs == 0) {
74b02f5
-      buf = getbuf(20);
74b02f5
-      sprintf((char*)buf.ptr, TAG_NAME[tag]);
74b02f5
+      return TAG_NAME[tag];
74b02f5
     } else if (nrefs == 1) {
74b02f5
       return refs[0]->string();
74b02f5
     } else {
74b02f5
-      char* s1 = refs[0]->string();
74b02f5
-      char* s2 = refs[1]->string();
74b02f5
-      buf = getbuf((int)strlen(s1) + 1 + (int)strlen(s2) + 4 + 1);
74b02f5
+      const char* s1 = refs[0]->string();
74b02f5
+      const char* s2 = refs[1]->string();
74b02f5
+      buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1);
74b02f5
       buf.strcat(s1).strcat(" ").strcat(s2);
74b02f5
       if (nrefs > 2)  buf.strcat(" ...");
74b02f5
     }
74b02f5
   }
74b02f5
-  return (char*)buf.ptr;
74b02f5
+  return (const char*)buf.ptr;
74b02f5
 }
74b02f5
 
74b02f5
 void print_cp_entry(int i) {
74b02f5
   entry& e = debug_u->cp.entries[i];
74b02f5
-  char buf[30];
74b02f5
-  sprintf(buf, ((uint)e.tag < CONSTANT_Limit)? TAG_NAME[e.tag]: "%d", e.tag);
74b02f5
-  printf(" %d\t%s %s\n", i, buf, e.string());
74b02f5
+
74b02f5
+  if ((uint)e.tag < CONSTANT_Limit) {
74b02f5
+    printf(" %d\t%s %s\n", i, TAG_NAME[e.tag], e.string());
74b02f5
+  } else {
74b02f5
+    printf(" %d\t%d %s\n", i, e.tag, e.string());
74b02f5
+  }
74b02f5
 }
74b02f5
 
74b02f5
 void print_cp_entries(int beg, int end) {
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.h openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.h
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.h
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.h
74b02f5
@@ -209,7 +209,7 @@
74b02f5
   byte*     rp;          // read pointer (< rplimit <= input.limit())
74b02f5
   byte*     rplimit;     // how much of the input block has been read?
74b02f5
   julong    bytes_read;
74b02f5
-  int       unsized_bytes_read;
74b02f5
+  size_t    unsized_bytes_read;
74b02f5
 
74b02f5
   // callback to read at least one byte, up to available input
74b02f5
   typedef jlong (*read_input_fn_t)(unpacker* self, void* buf, jlong minlen, jlong maxlen);
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.cpp openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.cpp
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.cpp
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.cpp
74b02f5
@@ -81,7 +81,7 @@
74b02f5
 int assert_failed(const char* p) {
74b02f5
   char message[1<<12];
74b02f5
   sprintf(message, "@assert failed: %s\n", p);
74b02f5
-  fprintf(stdout, 1+message);
74b02f5
+  fprintf(stdout, "%s", 1+message);
74b02f5
   breakpoint();
74b02f5
   unpack_abort(message);
74b02f5
   return 0;
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.cpp openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.cpp
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.cpp
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.cpp
74b02f5
@@ -84,7 +84,7 @@
74b02f5
 }
74b02f5
 
74b02f5
 // Write data to the ZIP output stream.
74b02f5
-void jar::write_data(void* buff, int len) {
74b02f5
+void jar::write_data(void* buff, size_t len) {
74b02f5
   while (len > 0) {
74b02f5
     int rc = (int)fwrite(buff, 1, len, jarfp);
74b02f5
     if (rc <= 0) {
74b02f5
@@ -323,12 +323,12 @@
74b02f5
     // Total number of disks (int)
74b02f5
     header64[36] = (ushort)SWAP_BYTES(1);
74b02f5
     header64[37] = 0;
74b02f5
-    write_data(header64, (int)sizeof(header64));
74b02f5
+    write_data(header64, sizeof(header64));
74b02f5
   }
74b02f5
 
74b02f5
   // Write the End of Central Directory structure.
74b02f5
   PRINTCR((2, "end-of-directory at %d\n", output_file_offset));
74b02f5
-  write_data(header, (int)sizeof(header));
74b02f5
+  write_data(header, sizeof(header));
74b02f5
 
74b02f5
   PRINTCR((2, "writing zip comment\n"));
74b02f5
   // Write the comment.
74b02f5
diff --git openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.h openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.h
74b02f5
--- openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.h
74b02f5
+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/zip.h
74b02f5
@@ -68,8 +68,8 @@
74b02f5
   }
74b02f5
 
74b02f5
   // Private Methods
74b02f5
-  void write_data(void* ptr, int len);
74b02f5
-  void write_data(bytes& b) { write_data(b.ptr, (int)b.len); }
74b02f5
+  void write_data(void* ptr, size_t len);
74b02f5
+  void write_data(bytes& b) { write_data(b.ptr, b.len); }
74b02f5
   void add_to_jar_directory(const char* fname, bool store, int modtime,
74b02f5
                             int len, int clen, uLong crc);
74b02f5
   void write_jar_header(const char* fname, bool store, int modtime,