Blame pr2462.patch

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