From 8e36b5da83de7f1212d0fdcac89abd1d744ca4f7 Mon Sep 17 00:00:00 2001 From: ohair Date: Sun, 17 Aug 2008 17:02:04 -0700 Subject: [PATCH] 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux Summary: Removal of compiler warnings and fixing of assert logic. Reviewed-by: jrose, ksrini, bristor --- .../com/sun/java/util/jar/pack/bands.cpp | 24 +- .../com/sun/java/util/jar/pack/bytes.cpp | 16 +- .../native/com/sun/java/util/jar/pack/bytes.h | 6 +- .../com/sun/java/util/jar/pack/coding.cpp | 51 ++-- .../com/sun/java/util/jar/pack/coding.h | 8 +- .../com/sun/java/util/jar/pack/defines.h | 24 +- .../native/com/sun/java/util/jar/pack/jni.cpp | 9 +- .../com/sun/java/util/jar/pack/main.cpp | 15 +- .../com/sun/java/util/jar/pack/unpack.cpp | 284 ++++++++++-------- .../com/sun/java/util/jar/pack/unpack.h | 16 +- .../com/sun/java/util/jar/pack/utils.cpp | 7 +- .../native/com/sun/java/util/jar/pack/utils.h | 4 +- .../native/com/sun/java/util/jar/pack/zip.cpp | 141 ++++----- .../native/com/sun/java/util/jar/pack/zip.h | 4 +- 14 files changed, 330 insertions(+), 279 deletions(-) diff --git a/src/share/native/com/sun/java/util/jar/pack/bands.cpp b/src/share/native/com/sun/java/util/jar/pack/bands.cpp index d900404de..c78644c28 100644 --- a/src/share/native/com/sun/java/util/jar/pack/bands.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/bands.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,15 +126,15 @@ void band::readData(int expectedLength) { (*save_meta_rp) = (byte) XB; cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null); (*save_meta_rp) = save_meta_xb; // put it back, just to be tidy - NOT_PRODUCT(cp2 = (u->meta_rp - meta_rp0)); + NOT_PRODUCT(cp2 = (int)(u->meta_rp - meta_rp0)); } rplimit = u->rp; rewind(); #ifndef PRODUCT - printcr(3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]", - (name?name:"(band)"), minRP(), length, size(), cp1, cp2); + PRINTCR((3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]", + (name?name:"(band)"), minRP(), length, size(), cp1, cp2)); if (u->verbose_bands || u->verbose >= 4) dump(); if (ix != null && u->verbose != 0 && length > 0) { @@ -421,18 +421,22 @@ const band_init all_band_inits[] = { BAND_INIT(file_modtime, DELTA5_spec, 0), BAND_INIT(file_options, UNSIGNED5_spec, 0), //BAND_INIT(file_bits, BYTE1_spec, 0), - {0} +#ifndef PRODUCT + { 0, 0, 0, 0 } +#else + { 0, 0 } +#endif }; #define NUM_BAND_INITS \ (sizeof(all_band_inits)/sizeof(all_band_inits[0])) band* band::makeBands(unpacker* u) { - band* all_bands = U_NEW(band, BAND_LIMIT); + band* tmp_all_bands = U_NEW(band, BAND_LIMIT); for (int i = 0; i < BAND_LIMIT; i++) { assert((byte*)&all_band_inits[i+1] < (byte*)all_band_inits+sizeof(all_band_inits)); const band_init& bi = all_band_inits[i]; - band& b = all_bands[i]; + band& b = tmp_all_bands[i]; coding* defc = coding::findBySpec(bi.defc); assert((defc == null) == (bi.defc == -1)); // no garbage, please assert(defc == null || !defc->isMalloc); @@ -446,13 +450,13 @@ band* band::makeBands(unpacker* u) { b.name = bi.name; #endif } - return all_bands; + return tmp_all_bands; } void band::initIndexes(unpacker* u) { - band* all_bands = u->all_bands; + band* tmp_all_bands = u->all_bands; for (int i = 0; i < BAND_LIMIT; i++) { - band* scan = &all_bands[i]; + band* scan = &tmp_all_bands[i]; uint tag = scan->ixTag; // Cf. #define INDEX(tag) above if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) { scan->setIndex(u->cp.getIndex(tag)); diff --git a/src/share/native/com/sun/java/util/jar/pack/bytes.cpp b/src/share/native/com/sun/java/util/jar/pack/bytes.cpp index 95c3dde66..ecc45ce2c 100644 --- a/src/share/native/com/sun/java/util/jar/pack/bytes.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/bytes.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,15 +71,17 @@ void bytes::realloc(size_t len_) { void bytes::free() { if (ptr == dummy) return; // escaping from an error - if (ptr != null) mtrace('f', ptr, 0); - if (ptr != null) ::free(ptr); + if (ptr != null) { + mtrace('f', ptr, 0); + ::free(ptr); + } len = 0; ptr = 0; } int bytes::indexOf(byte c) { byte* p = (byte*) memchr(ptr, c, len); - return (p == 0) ? -1 : p - ptr; + return (p == 0) ? -1 : (int)(p - ptr); } byte* bytes::writeTo(byte* bp) { @@ -174,8 +176,10 @@ void ptrlist::freeAll() { int len = length(); for (int i = 0; i < len; i++) { void* p = (void*) get(i); - if (p != null) mtrace('f', p, 0); - if (p != null) ::free(p); + if (p != null) { + mtrace('f', p, 0); + ::free(p); + } } free(); } diff --git a/src/share/native/com/sun/java/util/jar/pack/bytes.h b/src/share/native/com/sun/java/util/jar/pack/bytes.h index e0c0f6f59..f47b7eb05 100644 --- a/src/share/native/com/sun/java/util/jar/pack/bytes.h +++ b/src/share/native/com/sun/java/util/jar/pack/bytes.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -117,7 +117,7 @@ struct fillbytes { struct ptrlist : fillbytes { typedef const void* cvptr; - int length() { return size() / sizeof(cvptr); } + int length() { return (int)(size() / sizeof(cvptr)); } cvptr* base() { return (cvptr*) fillbytes::base(); } cvptr& get(int i) { return *(cvptr*)loc(i * sizeof(cvptr)); } cvptr* limit() { return (cvptr*) fillbytes::limit(); } @@ -133,7 +133,7 @@ struct ptrlist : fillbytes { ::qsort((ptrls).base(), (ptrls).length(), sizeof(void*), fn) struct intlist : fillbytes { - int length() { return size() / sizeof(int); } + int length() { return (int)(size() / sizeof(int)); } int* base() { return (int*) fillbytes::base(); } int& get(int i) { return *(int*)loc(i * sizeof(int)); } int* limit() { return (int*) fillbytes::limit(); } diff --git a/src/share/native/com/sun/java/util/jar/pack/coding.cpp b/src/share/native/com/sun/java/util/jar/pack/coding.cpp index d3ec4ae0e..dec681ccf 100644 --- a/src/share/native/com/sun/java/util/jar/pack/coding.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/coding.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -113,7 +113,7 @@ coding* coding::init() { jlong maxNegCode = range-1; while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode; while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode; - int maxPos = decode_sign(S, maxPosCode); + int maxPos = decode_sign(S, (uint)maxPosCode); if (maxPos < 0) this->max = INT_MAX_VALUE; // 32-bit wraparound else @@ -121,7 +121,7 @@ coding* coding::init() { if (maxNegCode < 0) this->min = 0; // No negative codings at all. else - this->min = decode_sign(S, maxNegCode); + this->min = decode_sign(S, (uint)maxNegCode); } } @@ -149,10 +149,10 @@ coding* coding::findBySpec(int spec) { coding* ptr = NEW(coding, 1); CHECK_NULL_0(ptr); coding* c = ptr->initFrom(spec); - if (c == null) mtrace('f', ptr, 0); - if (c == null) + if (c == null) { + mtrace('f', ptr, 0); ::free(ptr); - else + } else // else caller should free it... c->isMalloc = true; return c; @@ -167,9 +167,10 @@ coding* coding::findBySpec(int B, int H, int S, int D) { } void coding::free() { - if (isMalloc) mtrace('f', this, 0); - if (isMalloc) + if (isMalloc) { + mtrace('f', this, 0); ::free(this); + } } void coding_method::reset(value_stream* state) { @@ -187,7 +188,7 @@ uint coding::parse(byte* &rp, int B, int H) { byte* ptr = rp; // hand peel the i==0 part of the loop: uint b_i = *ptr++ & 0xFF; - if (B == 1 || b_i < L) + if (B == 1 || b_i < (uint)L) { rp = ptr; return b_i; } uint sum = b_i; uint H_i = H; @@ -195,7 +196,7 @@ uint coding::parse(byte* &rp, int B, int H) { for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired b_i = *ptr++ & 0xFF; sum += b_i * H_i; - if (i == B || b_i < L) + if (i == B || b_i < (uint)L) { rp = ptr; return sum; } H_i *= H; } @@ -210,7 +211,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) { byte* ptr = rp; // hand peel the i==0 part of the loop: uint b_i = *ptr++ & 0xFF; - if (B == 1 || b_i < L) + if (B == 1 || b_i < (uint)L) { rp = ptr; return b_i; } uint sum = b_i; uint lg_H_i = lgH; @@ -218,7 +219,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) { for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired b_i = *ptr++ & 0xFF; sum += b_i << lg_H_i; - if (i == B || b_i < L) + if (i == B || b_i < (uint)L) { rp = ptr; return sum; } lg_H_i += lgH; } @@ -237,7 +238,7 @@ void coding::parseMultiple(byte* &rp, int N, byte* limit, int B, int H) { byte* ptr = rp; if (B == 1 || H == 256) { size_t len = (size_t)N*B; - if (len / B != N || ptr+len > limit) { + if (len / B != (size_t)N || ptr+len > limit) { abort(ERB); return; } @@ -325,7 +326,7 @@ static maybe_inline int getPopValue(value_stream* self, uint uval) { if (uval > 0) { // note that the initial parse performed a range check - assert(uval <= self->cm->fVlength); + assert(uval <= (uint)self->cm->fVlength); return self->cm->fValues[uval-1]; } else { // take an unfavored value @@ -368,7 +369,7 @@ int coding::sumInUnsignedRange(int x, int y) { static maybe_inline int getDeltaValue(value_stream* self, uint uval, bool isSubrange) { - assert((bool)(self->c.isSubrange) == isSubrange); + assert((uint)(self->c.isSubrange) == (uint)isSubrange); assert(self->c.isSubrange | self->c.isFullRange); if (isSubrange) return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval); @@ -443,7 +444,7 @@ int value_stream::getInt() { uval = coding::parse(rp, B, H); if (S != 0) uval = (uint) decode_sign(S, uval); - return getDeltaValue(this, uval, c.isSubrange); + return getDeltaValue(this, uval, (bool)c.isSubrange); case cmk_BHS1D1full: assert(S == 1 && D == 1 && c.isFullRange); @@ -499,6 +500,9 @@ int value_stream::getInt() { assert(c.spec == BYTE1_spec); assert(B == 1 && H == 256 && S == 0 && D == 0); return getPopValue(this, *rp++ & 0xFF); + + default: + break; } assert(false); return 0; @@ -695,7 +699,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit, for (int i = 0; i < N; i++) { uint val = vs.getInt(); if (val == 0) UN += 1; - if (!(val <= fVlength)) { + if (!(val <= (uint)fVlength)) { abort("pop token out of range"); return; } @@ -728,6 +732,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit, switch (self->vs0.cmk) { case cmk_BHS0: cmk2 = cmk_pop_BHS0; break; case cmk_BYTE1: cmk2 = cmk_pop_BYTE1; break; + default: break; } self->vs0.cmk = cmk2; if (self != this) { @@ -947,15 +952,17 @@ coding basic_codings[] = { CODING_INIT(4,240,1,1), CODING_INIT(4,248,0,1), CODING_INIT(4,248,1,1), - - 0 + CODING_INIT(0,0,0,0) }; #define BASIC_INDEX_LIMIT \ - (sizeof(basic_codings)/sizeof(basic_codings[0])-1) + (int)(sizeof(basic_codings)/sizeof(basic_codings[0])-1) coding* coding::findByIndex(int idx) { - assert(_meta_canon_min == 1); - assert(_meta_canon_max+1 == BASIC_INDEX_LIMIT); +#ifndef PRODUCT + /* Tricky assert here, constants and gcc complains about it without local. */ + int index_limit = BASIC_INDEX_LIMIT; + assert(_meta_canon_min == 1 && _meta_canon_max+1 == index_limit); +#endif if (idx >= _meta_canon_min && idx <= _meta_canon_max) return basic_codings[idx].init(); else diff --git a/src/share/native/com/sun/java/util/jar/pack/coding.h b/src/share/native/com/sun/java/util/jar/pack/coding.h index 4259915d8..65a036215 100644 --- a/src/share/native/com/sun/java/util/jar/pack/coding.h +++ b/src/share/native/com/sun/java/util/jar/pack/coding.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,9 +35,11 @@ struct unpacker; #define CODING_D(x) ((x)>>0 & 0xF) #define CODING_INIT(B, H, S, D) \ - { CODING_SPEC(B, H, S, D) } + { CODING_SPEC(B, H, S, D) , 0, 0, 0, 0, 0, 0, 0, 0} -#define long do_not_use_C_long_types_use_jlong_or_int +// For debugging purposes, some compilers do not like this and will complain. +// #define long do_not_use_C_long_types_use_jlong_or_int +// Use of the type "long" is problematic, do not use it. struct coding { int spec; // B,H,S,D diff --git a/src/share/native/com/sun/java/util/jar/pack/defines.h b/src/share/native/com/sun/java/util/jar/pack/defines.h index 19f7567e7..0bf25d5b0 100644 --- a/src/share/native/com/sun/java/util/jar/pack/defines.h +++ b/src/share/native/com/sun/java/util/jar/pack/defines.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,15 +45,15 @@ #ifdef PRODUCT #define IF_PRODUCT(xxx) xxx #define NOT_PRODUCT(xxx) -#define assert(p) (0) -#define printcr false && +#define assert(p) +#define PRINTCR(args) #else #define IF_PRODUCT(xxx) #define NOT_PRODUCT(xxx) xxx -#define assert(p) ((p) || (assert_failed(#p), 1)) -#define printcr u->verbose && u->printcr_if_verbose +#define assert(p) ((p) || assert_failed(#p)) +#define PRINTCR(args) u->verbose && u->printcr_if_verbose args extern "C" void breakpoint(); -extern void assert_failed(const char*); +extern int assert_failed(const char*); #define BREAK (breakpoint()) #endif @@ -79,7 +79,7 @@ extern void assert_failed(const char*); #define lengthof(array) (sizeof(array)/sizeof(array[0])) -#define NEW(T, n) (T*) must_malloc(sizeof(T)*(n)) +#define NEW(T, n) (T*) must_malloc((int)(sizeof(T)*(n))) #define U_NEW(T, n) (T*) u->alloc(sizeof(T)*(n)) #define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n)) @@ -121,12 +121,12 @@ enum { false, true }; #define null (0) -#ifndef __sparc -#define intptr_t jlong -#endif - -#define ptrlowbits(x) ((int) (intptr_t)(x)) +/* Must cast to void *, then size_t, then int. */ +#define ptrlowbits(x) ((int)(size_t)(void*)(x)) +/* Back and forth from jlong to pointer */ +#define ptr2jlong(x) ((jlong)(size_t)(void*)(x)) +#define jlong2ptr(x) ((void*)(size_t)(x)) // Keys used by Java: #define UNPACK_DEFLATE_HINT "unpack.deflate.hint" diff --git a/src/share/native/com/sun/java/util/jar/pack/jni.cpp b/src/share/native/com/sun/java/util/jar/pack/jni.cpp index d217341da..eb9898278 100644 --- a/src/share/native/com/sun/java/util/jar/pack/jni.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/jni.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,7 +59,8 @@ static jlong read_input_via_jni(unpacker* self, void* buf, jlong minlen, jlong maxlen); static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) { - unpacker* uPtr = (unpacker*) env->GetLongField(pObj, unpackerPtrFID); + unpacker* uPtr; + uPtr = (unpacker*)jlong2ptr(env->GetLongField(pObj, unpackerPtrFID)); //fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr); if (uPtr == null) { if (noCreate) return null; @@ -71,7 +72,7 @@ static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) { //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr); uPtr->init(read_input_via_jni); uPtr->jniobj = (void*) env->NewGlobalRef(pObj); - env->SetLongField(pObj, unpackerPtrFID, (jlong)uPtr); + env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr)); } uPtr->jnienv = env; // keep refreshing this in case of MT access return uPtr; @@ -150,7 +151,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj, size_t buflen = 0; if (pBuf != null) { buf = env->GetDirectBufferAddress(pBuf); - buflen = env->GetDirectBufferCapacity(pBuf); + buflen = (size_t)env->GetDirectBufferCapacity(pBuf); if (buflen == 0) buf = null; if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; } if ((size_t)offset >= buflen) diff --git a/src/share/native/com/sun/java/util/jar/pack/main.cpp b/src/share/native/com/sun/java/util/jar/pack/main.cpp index 9e216cd19..789841d22 100644 --- a/src/share/native/com/sun/java/util/jar/pack/main.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -86,13 +86,13 @@ static jlong read_input_via_stdio(unpacker* u, readlen = (int)(maxlen - numread); int nr = 0; if (u->infileptr != null) { - nr = fread(bufptr, 1, readlen, u->infileptr); + nr = (int)fread(bufptr, 1, readlen, u->infileptr); } else { #ifndef WIN32 // we prefer unbuffered inputs - nr = read(u->infileno, bufptr, readlen); + nr = (int)read(u->infileno, bufptr, readlen); #else - nr = fread(bufptr, 1, readlen, stdin); + nr = (int)fread(bufptr, 1, readlen, stdin); #endif } if (nr <= 0) { @@ -279,7 +279,6 @@ int unpacker::run(int argc, char **argv) { char** argbuf = init_args(argc, argv, envargc); char** arg0 = argbuf+envargc; char** argp = argbuf; - int ach; int verbose = 0; char* logfile = null; @@ -370,7 +369,7 @@ int unpacker::run(int argc, char **argv) { int magic; // check for GZIP input - magic = read_magic(&u, peek, sizeof(peek)); + magic = read_magic(&u, peek, (int)sizeof(peek)); if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC) { // Oops; must slap an input filter on this data. setup_gzin(&u); @@ -397,8 +396,8 @@ int unpacker::run(int argc, char **argv) { if (u.aborting()) break; // Peek ahead for more data. - magic = read_magic(&u, peek, sizeof(peek)); - if (magic != JAVA_PACKAGE_MAGIC) { + magic = read_magic(&u, peek, (int)sizeof(peek)); + if (magic != (int)JAVA_PACKAGE_MAGIC) { if (magic != EOF_MAGIC) u.abort("garbage after end of pack archive"); break; // all done diff --git a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp index 6480da700..90b9f72e4 100644 --- a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,21 @@ // Program for unpacking specially compressed Java packages. // John R. Rose +/* + * When compiling for a 64bit LP64 system (longs and pointers being 64bits), + * the printf format %ld is correct and use of %lld will cause warning + * errors from some compilers (gcc/g++). + * _LP64 can be explicitly set (used on Linux). + * Solaris compilers will define __sparcv9 or __x86_64 on 64bit compilations. + */ +#if defined(_LP64) || defined(__sparcv9) || defined(__x86_64) + #define LONG_LONG_FORMAT "%ld" + #define LONG_LONG_HEX_FORMAT "%lx" +#else + #define LONG_LONG_FORMAT "%lld" + #define LONG_LONG_HEX_FORMAT "%016llx" +#endif + #include #include @@ -253,12 +268,12 @@ int entry::typeSize() { inline cpindex* cpool::getFieldIndex(entry* classRef) { assert(classRef->tagMatches(CONSTANT_Class)); - assert((uint)classRef->inord < tag_count[CONSTANT_Class]); + assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]); return &member_indexes[classRef->inord*2+0]; } inline cpindex* cpool::getMethodIndex(entry* classRef) { assert(classRef->tagMatches(CONSTANT_Class)); - assert((uint)classRef->inord < tag_count[CONSTANT_Class]); + assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]); return &member_indexes[classRef->inord*2+1]; } @@ -341,7 +356,7 @@ bool unpacker::ensure_input(jlong more) { rplimit += nr; fetch -= nr; bytes_read += nr; - assert(remaining == (input.limit() - rplimit)); + assert(remaining == (julong)(input.limit() - rplimit)); } return true; } @@ -441,9 +456,13 @@ int unpacker::putref_index(entry* e, int size) { e->requestOutputIndex(cp, -size); // Later on we'll fix the bits. class_fixup_type.addByte(size); - class_fixup_offset.add(wpoffset()); + class_fixup_offset.add((int)wpoffset()); class_fixup_ref.add(e); - return !assert(1) ? 0 : 0x20+size; // 0x22 is easy to eyeball +#ifdef PRODUCT + return 0; +#else + return 0x20+size; // 0x22 is easy to eyeball +#endif } } @@ -472,7 +491,7 @@ enum { CHUNK = (1 << 14), SMALL = (1 << 9) }; void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) { CHECK_0; if (!smallOK || size > SMALL) { - void* res = must_malloc(size); + void* res = must_malloc((int)size); (temp ? &tmallocs : &mallocs)->add(res); return res; } @@ -481,7 +500,7 @@ void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) { xsmallbuf.init(CHUNK); (temp ? &tmallocs : &mallocs)->add(xsmallbuf.base()); } - int growBy = size; + int growBy = (int)size; growBy += -growBy & 7; // round up mod 8 return xsmallbuf.grow(growBy); } @@ -514,7 +533,7 @@ void unpacker::read_file_header() { FIRST_READ = MAGIC_BYTES + AH_LENGTH_MIN }; bool foreign_buf = (read_input_fn == null); - byte initbuf[FIRST_READ + C_SLOP + 200]; // 200 is for JAR I/O + byte initbuf[(int)FIRST_READ + (int)C_SLOP + 200]; // 200 is for JAR I/O if (foreign_buf) { // inbytes is all there is input.set(inbytes); @@ -553,7 +572,7 @@ void unpacker::read_file_header() { // Copy until EOF; assume the JAR file is the last segment. fprintf(errstrm, "Copy-mode.\n"); for (;;) { - jarout->write_data(rp, input_remaining()); + jarout->write_data(rp, (int)input_remaining()); if (foreign_buf) break; // one-time use of a passed in buffer if (input.size() < CHUNK) { @@ -572,7 +591,7 @@ void unpacker::read_file_header() { // Read the magic number. magic = 0; - for (int i1 = 0; i1 < sizeof(magic); i1++) { + for (int i1 = 0; i1 < (int)sizeof(magic); i1++) { magic <<= 8; magic += (*rp++ & 0xFF); } @@ -586,7 +605,7 @@ void unpacker::read_file_header() { majver = hdr.getInt(); hdrVals += 2; - if (magic != JAVA_PACKAGE_MAGIC || + if (magic != (int)JAVA_PACKAGE_MAGIC || (majver != JAVA5_PACKAGE_MAJOR_VERSION && majver != JAVA6_PACKAGE_MAJOR_VERSION) || (minver != JAVA5_PACKAGE_MINOR_VERSION && @@ -633,19 +652,19 @@ void unpacker::read_file_header() { // Now we can size the whole archive. // Read everything else into a mega-buffer. rp = hdr.rp; - int header_size_0 = (rp - input.base()); // used-up header (4byte + 3int) - int header_size_1 = (rplimit - rp); // buffered unused initial fragment + int header_size_0 = (int)(rp - input.base()); // used-up header (4byte + 3int) + int header_size_1 = (int)(rplimit - rp); // buffered unused initial fragment int header_size = header_size_0+header_size_1; unsized_bytes_read = header_size_0; CHECK; if (foreign_buf) { - if (archive_size > header_size_1) { + if (archive_size > (size_t)header_size_1) { abort("EOF reading fixed input buffer"); return; } } else if (archive_size > 0) { - input.set(U_NEW(byte, (size_t) header_size_0 + archive_size + C_SLOP), - (size_t) header_size_0 + archive_size); + input.set(U_NEW(byte, (size_t)(header_size_0 + archive_size + C_SLOP)), + (size_t) header_size_0 + (size_t)archive_size); assert(input.limit()[0] == 0); // Move all the bytes we read initially into the real buffer. input.b.copyFrom(initbuf, header_size); @@ -712,7 +731,7 @@ void unpacker::read_file_header() { } int cp_counts[N_TAGS_IN_ORDER]; - for (int k = 0; k < N_TAGS_IN_ORDER; k++) { + for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { if (!(archive_options & AO_HAVE_CP_NUMBERS)) { switch (TAGS_IN_ORDER[k]) { case CONSTANT_Integer: @@ -753,7 +772,10 @@ void unpacker::read_file_header() { abort("EOF reading archive header"); // Now size the CP. - assert(N_TAGS_IN_ORDER == cpool::NUM_COUNTS); +#ifndef PRODUCT + bool x = (N_TAGS_IN_ORDER == cpool::NUM_COUNTS); + assert(x); +#endif //PRODUCT cp.init(this, cp_counts); CHECK; @@ -766,7 +788,7 @@ void unpacker::read_file_header() { // meta-bytes, if any, immediately follow archive header //band_headers.readData(band_headers_size); ensure_input(band_headers_size); - if (input_remaining() < band_headers_size) { + if (input_remaining() < (size_t)band_headers_size) { abort("EOF reading band headers"); return; } @@ -789,12 +811,14 @@ void unpacker::read_file_header() { void unpacker::finish() { if (verbose >= 1) { fprintf(errstrm, - "A total of %lld bytes were read in %d segment(s).\n", - bytes_read_before_reset+bytes_read, + "A total of " + LONG_LONG_FORMAT " bytes were read in %d segment(s).\n", + (bytes_read_before_reset+bytes_read), segments_read_before_reset+1); fprintf(errstrm, - "A total of %lld file content bytes were written.\n", - bytes_written_before_reset+bytes_written); + "A total of " + LONG_LONG_FORMAT " file content bytes were written.\n", + (bytes_written_before_reset+bytes_written)); fprintf(errstrm, "A total of %d files (of which %d are classes) were written to output.\n", files_written_before_reset+files_written, @@ -822,7 +846,7 @@ void cpool::init(unpacker* u_, int counts[NUM_COUNTS]) { int next_entry = 0; // Size the constant pool: - for (int k = 0; k < N_TAGS_IN_ORDER; k++) { + for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { byte tag = TAGS_IN_ORDER[k]; int len = counts[k]; tag_count[tag] = len; @@ -902,8 +926,8 @@ static byte* skip_Utf8_chars(byte* cp, int len) { } static int compare_Utf8_chars(bytes& b1, bytes& b2) { - int l1 = b1.len; - int l2 = b2.len; + int l1 = (int)b1.len; + int l2 = (int)b2.len; int l0 = (l1 < l2) ? l1 : l2; byte* p1 = b1.ptr; byte* p2 = b2.ptr; @@ -949,10 +973,12 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { // First band: Read lengths of shared prefixes. if (len > PREFIX_SKIP_2) cp_Utf8_prefix.readData(len - PREFIX_SKIP_2); + NOT_PRODUCT(else cp_Utf8_prefix.readData(0)); // for asserts // Second band: Read lengths of unshared suffixes: if (len > SUFFIX_SKIP_1) cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1); + NOT_PRODUCT(else cp_Utf8_suffix.readData(0)); // for asserts bytes* allsuffixes = T_NEW(bytes, len); CHECK; @@ -999,7 +1025,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { CHECK; tmallocs.add(chars.ptr); // free it later } else { - int shrink = chars.limit() - chp; + int shrink = (int)(chars.limit() - chp); chars.len -= shrink; charbuf.b.len -= shrink; // ungrow to reclaim buffer space // Note that we did not reclaim the final '\0'. @@ -1008,7 +1034,9 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { } } //cp_Utf8_chars.done(); - if (assert(1)) charbuf.b.set(null, 0); // tidy +#ifndef PRODUCT + charbuf.b.set(null, 0); // tidy +#endif // Fourth band: Go back and size the specially packed strings. int maxlen = 0; @@ -1041,7 +1069,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { for (i = 0; i < len; i++) { bytes& chars = allsuffixes[i]; if (chars.ptr != null) continue; // already input - int suffix = chars.len; // pick up the hack + int suffix = (int)chars.len; // pick up the hack uint size3 = suffix * 3; if (suffix == 0) continue; // done with empty string chars.malloc(size3); @@ -1071,7 +1099,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { for (i = 0; i < len; i++) { bytes& chars = allsuffixes[i]; int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt(); - int suffix = chars.len; + int suffix = (int)chars.len; byte* fillp; // by induction, the buffer is already filled with the prefix // make sure the prefix value is not corrupted, though: @@ -1084,7 +1112,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) { fillp = chars.writeTo(fillp); assert(bigbuf.inBounds(fillp)); *fillp = 0; // bigbuf must contain a well-formed Utf8 string - int length = fillp - bigbuf.ptr; + int length = (int)(fillp - bigbuf.ptr); bytes& value = cpMap[i].value.b; value.set(U_NEW(byte, length+1), length); value.copyFrom(bigbuf.ptr, length); @@ -1215,12 +1243,12 @@ void unpacker::read_cp() { int i; - for (int k = 0; k < N_TAGS_IN_ORDER; k++) { + for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { byte tag = TAGS_IN_ORDER[k]; int len = cp.tag_count[tag]; int base = cp.tag_base[tag]; - printcr(1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0); + PRINTCR((1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0)); entry* cpMap = &cp.entries[base]; for (i = 0; i < len; i++) { cpMap[i].tag = tag; @@ -1282,7 +1310,7 @@ void unpacker::read_cp() { #ifndef PRODUCT cpindex* ix = &cp.tag_index[tag]; assert(ix->ixTag == tag); - assert(ix->len == len); + assert((int)ix->len == len); assert(ix->base1 == cpMap); #endif CHECK; @@ -1293,7 +1321,7 @@ void unpacker::read_cp() { cp.initMemberIndexes(); CHECK; - printcr(1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0)); + PRINTCR((1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0))); #define SNAME(n,s) #s "\0" const char* symNames = ( @@ -1307,7 +1335,7 @@ void unpacker::read_cp() { bytes name; name.set(symNames); if (name.len > 0 && name.ptr[0] != '0') { cp.sym[sn] = cp.ensureUtf8(name); - printcr(4, "well-known sym %d=%s", sn, cp.sym[sn]->string()); + PRINTCR((4, "well-known sym %d=%s", sn, cp.sym[sn]->string())); } symNames += name.len + 1; // skip trailing null to next name } @@ -1352,7 +1380,7 @@ unpacker::attr_definitions::defineLayout(int idx, assert(flag_limit != 0); // must be set up already if (idx >= 0) { // Fixed attr. - if (idx >= flag_limit) + if (idx >= (int)flag_limit) abort("attribute index too large"); if (isRedefined(idx)) abort("redefined attribute index"); @@ -1635,7 +1663,7 @@ unpacker::attr_definitions::parseLayout(const char* lp, band** &res, for (;;) { int caseval = 0; lp = parseNumeral(lp, caseval); - band_stack.add((void*)caseval); + band_stack.add((void*)(size_t)caseval); if (*lp == '-') { // new in version 160, allow (1-5) for (1,2,3,4,5) if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) { @@ -1654,7 +1682,7 @@ unpacker::attr_definitions::parseLayout(const char* lp, band** &res, } for (;;) { ++caseval; - band_stack.add((void*)caseval); + band_stack.add((void*)(size_t)caseval); if (caseval == caselimit) break; } } @@ -1921,7 +1949,7 @@ static int lastIndexOf(int chmin, int chmax, bytes& x, int pos) { for (byte* cp = ptr + pos; --cp >= ptr; ) { assert(x.inBounds(cp)); if (*cp >= chmin && *cp <= chmax) - return cp - ptr; + return (int)(cp - ptr); } return -1; } @@ -1976,7 +2004,7 @@ void unpacker::read_ics() { entry* inner = ic_this_class.getRef(); CHECK; uint inord = inner->inord; - assert(inord < cp.tag_count[CONSTANT_Class]); + assert(inord < (uint)cp.tag_count[CONSTANT_Class]); if (ic_index[inord] != null) { abort("identical inner class"); break; @@ -2003,10 +2031,10 @@ void unpacker::read_ics() { bytes number; bytes name; // Parse n into pkgOuter and name (and number). - printcr(5, "parse short IC name %s", n.ptr); + PRINTCR((5, "parse short IC name %s", n.ptr)); int dollar1, dollar2; // pointers to $ in the pattern // parse n = (/)*($)?($)? - int nlen = n.len; + int nlen = (int)n.len; int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1; dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen); if (dollar2 < 0) { @@ -2035,8 +2063,8 @@ void unpacker::read_ics() { pkgOuter = n.slice(0, dollar1); else pkgOuter.set(null,0); - printcr(5,"=> %s$ 0%s $%s", - pkgOuter.string(), number.string(), name.string()); + PRINTCR((5,"=> %s$ 0%s $%s", + pkgOuter.string(), number.string(), name.string())); if (pkgOuter.ptr != null) ics[i].outer = cp.ensureClass(pkgOuter); @@ -2049,7 +2077,7 @@ void unpacker::read_ics() { if (ics[i].outer != null) { uint outord = ics[i].outer->inord; if (outord != NO_INORD) { - assert(outord < cp.tag_count[CONSTANT_Class]); + assert(outord < (uint)cp.tag_count[CONSTANT_Class]); ics[i].next_sibling = ic_child_index[outord]; ic_child_index[outord] = &ics[i]; } @@ -2060,8 +2088,7 @@ void unpacker::read_ics() { } void unpacker::read_classes() { - int i; - printcr(1," ...scanning %d classes...", class_count); + PRINTCR((1," ...scanning %d classes...", class_count)); class_this.readData(class_count); class_super.readData(class_count); class_interface_count.readData(class_count); @@ -2070,6 +2097,7 @@ void unpacker::read_classes() { CHECK; #if 0 + int i; // Make a little mark on super-classes. for (i = 0; i < class_count; i++) { entry* e = class_super.getRefN(); @@ -2099,8 +2127,8 @@ void unpacker::read_classes() { read_code_headers(); - printcr(1,"scanned %d classes, %d fields, %d methods, %d code headers", - class_count, field_count, method_count, code_count); + PRINTCR((1,"scanned %d classes, %d fields, %d methods, %d code headers", + class_count, field_count, method_count, code_count)); } maybe_inline @@ -2137,7 +2165,7 @@ void unpacker::read_attrs(int attrc, int obj_count) { } indexBits &= indexMask; // ignore classfile flag bits for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) { - ad.flag_count[idx] += (indexBits & 1); + ad.flag_count[idx] += (int)(indexBits & 1); } } // we'll scan these again later for output: @@ -2337,7 +2365,7 @@ void unpacker::read_attrs(int attrc, int obj_count) { for (idx = 0; idx < ad.layouts.length(); idx++) { if (ad.getLayout(idx) == null) continue; // none at this fixed index <32 - if (idx < ad.flag_limit && ad.isPredefined(idx)) + if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) continue; // already handled if (ad.getCount(idx) == 0) continue; // no attributes of this type (then why transmit layouts?) @@ -2351,9 +2379,9 @@ void unpacker::attr_definitions::readBandData(int idx) { if (count == 0) return; layout_definition* lo = getLayout(idx); if (lo != null) { - printcr(1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s", + PRINTCR((1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s", count, isRedefined(idx), isPredefined(idx), - ATTR_CONTEXT_NAME[attrc], lo->name); + ATTR_CONTEXT_NAME[attrc], lo->name)); } bool hasCallables = lo->hasCallables(); band** bands = lo->bands(); @@ -2376,13 +2404,13 @@ void unpacker::attr_definitions::readBandData(int idx) { } } // Now consult whichever callables have non-zero entry counts. - readBandData(bands, -1); + readBandData(bands, (uint)-1); } } // Recursive helper to the previous function: void unpacker::attr_definitions::readBandData(band** body, uint count) { - int i, j, k; + int j, k; for (j = 0; body[j] != null; j++) { band& b = *body[j]; if (b.defc != null) { @@ -2427,7 +2455,7 @@ void unpacker::attr_definitions::readBandData(band** body, uint count) { } break; case EK_CBLE: - assert(count == -1); // incoming count is meaningless + assert((int)count == -1); // incoming count is meaningless k = b.length; assert(k >= 0); // This is intended and required for non production mode. @@ -2490,7 +2518,7 @@ void unpacker::putlayout(band** body) { assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN); x = b.getInt(); - assert(!b.le_bci || prevBCI == to_bci(prevBII)); + assert(!b.le_bci || prevBCI == (int)to_bci(prevBII)); switch (b.le_bci) { case EK_BCI: // PH: transmit R(bci), store bci x = to_bci(prevBII = x); @@ -2505,7 +2533,7 @@ void unpacker::putlayout(band** body) { prevBCI += x; break; } - assert(!b.le_bci || prevBCI == to_bci(prevBII)); + assert(!b.le_bci || prevBCI == (int)to_bci(prevBII)); switch (b.le_len) { case 0: break; @@ -2721,8 +2749,8 @@ band* unpacker::ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar) { // Cf. PackageReader.readByteCodes inline // called exactly once => inline void unpacker::read_bcs() { - printcr(3, "reading compressed bytecodes and operands for %d codes...", - code_count); + PRINTCR((3, "reading compressed bytecodes and operands for %d codes...", + code_count)); // read from bc_codes and bc_case_count fillbytes all_switch_ops; @@ -2825,18 +2853,18 @@ void unpacker::read_bcs() { // Go through the formality, so we can use it in a regular fashion later: assert(rp == rp0); - bc_codes.readData(opptr - rp); + bc_codes.readData((int)(opptr - rp)); int i = 0; // To size instruction bands correctly, we need info on switches: - bc_case_count.readData(all_switch_ops.size()); - for (i = 0; i < all_switch_ops.size(); i++) { + bc_case_count.readData((int)all_switch_ops.size()); + for (i = 0; i < (int)all_switch_ops.size(); i++) { int caseCount = bc_case_count.getInt(); int bc = all_switch_ops.getByte(i); bc_label.expectMoreLength(1+caseCount); // default label + cases bc_case_value.expectMoreLength(bc == bc_tableswitch ? 1 : caseCount); - printcr(2, "switch bc=%d caseCount=%d", bc, caseCount); + PRINTCR((2, "switch bc=%d caseCount=%d", bc, caseCount)); } bc_case_count.rewind(); // uses again for output @@ -2849,15 +2877,14 @@ void unpacker::read_bcs() { // The bc_escbyte band is counted by the immediately previous band. bc_escbyte.readData(bc_escsize.getIntTotal()); - printcr(3, "scanned %d opcode and %d operand bytes for %d codes...", + PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...", (int)(bc_codes.size()), (int)(bc_escsize.maxRP() - bc_case_value.minRP()), - code_count); + code_count)); } void unpacker::read_bands() { byte* rp0 = rp; - int i; read_file_header(); CHECK; @@ -2886,9 +2913,9 @@ void unpacker::read_bands() { /// CP routines entry*& cpool::hashTabRef(byte tag, bytes& b) { - printcr(5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len); - uint hash = tag + b.len; - for (int i = 0; i < b.len; i++) { + PRINTCR((5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len)); + uint hash = tag + (int)b.len; + for (int i = 0; i < (int)b.len; i++) { hash = hash * 31 + (0xFF & b.ptr[i]); } entry** ht = hashTab; @@ -2905,15 +2932,15 @@ entry*& cpool::hashTabRef(byte tag, bytes& b) { // Note: hash2 must be relatively prime to hlen, hence the "|1". hash2 = (((hash % 499) & (hlen-1)) | 1); hash1 += hash2; - if (hash1 >= hlen) hash1 -= hlen; - assert(hash1 < hlen); + if (hash1 >= (uint)hlen) hash1 -= hlen; + assert(hash1 < (uint)hlen); assert(++probes < hlen); } #ifndef PRODUCT hash_probes[0] += 1; hash_probes[1] += probes; #endif - printcr(5, " => @%d %p", hash1, ht[hash1]); + PRINTCR((5, " => @%d %p", hash1, ht[hash1])); return ht[hash1]; } @@ -2939,7 +2966,7 @@ entry* cpool::ensureUtf8(bytes& b) { u->saveTo(e.value.b, b); assert(&e >= first_extra_entry); insert_extra(&e, tag_extras[CONSTANT_Utf8]); - printcr(4,"ensureUtf8 miss %s", e.string()); + PRINTCR((4,"ensureUtf8 miss %s", e.string())); return ix = &e; } @@ -2961,7 +2988,7 @@ entry* cpool::ensureClass(bytes& b) { e.value.b = utf->value.b; assert(&e >= first_extra_entry); insert_extra(&e, tag_extras[CONSTANT_Class]); - printcr(4,"ensureClass miss %s", e.string()); + PRINTCR((4,"ensureClass miss %s", e.string())); return &e; } @@ -2980,7 +3007,7 @@ void cpool::expandSignatures() { int refnum = 0; bytes form = e.refs[refnum++]->asUtf8(); buf.empty(); - for (int j = 0; j < form.len; j++) { + for (int j = 0; j < (int)form.len; j++) { int c = form.ptr[j]; buf.addByte(c); if (c == 'L') { @@ -2990,7 +3017,7 @@ void cpool::expandSignatures() { } assert(refnum == e.nrefs); bytes& sig = buf.b; - printcr(5,"signature %d %s -> %s", i, form.ptr, sig.ptr); + PRINTCR((5,"signature %d %s -> %s", i, form.ptr, sig.ptr)); // try to find a pre-existing Utf8: entry* &e2 = hashTabRef(CONSTANT_Utf8, sig); @@ -2999,7 +3026,7 @@ void cpool::expandSignatures() { e.value.b = e2->value.b; e.refs[0] = e2; e.nrefs = 1; - printcr(5,"signature replaced %d => %s", i, e.string()); + PRINTCR((5,"signature replaced %d => %s", i, e.string())); nreused++; } else { // there is no other replacement; reuse this CP entry as a Utf8 @@ -3007,15 +3034,15 @@ void cpool::expandSignatures() { e.tag = CONSTANT_Utf8; e.nrefs = 0; e2 = &e; - printcr(5,"signature changed %d => %s", e.inord, e.string()); + PRINTCR((5,"signature changed %d => %s", e.inord, e.string())); } nsigs++; } - printcr(1,"expanded %d signatures (reused %d utfs)", nsigs, nreused); + PRINTCR((1,"expanded %d signatures (reused %d utfs)", nsigs, nreused)); buf.free(); // go expunge all references to remaining signatures: - for (i = 0; i < nentries; i++) { + for (i = 0; i < (int)nentries; i++) { entry& e = entries[i]; for (int j = 0; j < e.nrefs; j++) { entry*& e2 = e.refs[j]; @@ -3028,7 +3055,7 @@ void cpool::expandSignatures() { void cpool::initMemberIndexes() { // This function does NOT refer to any class schema. // It is totally internal to the cpool. - int i, j, len; + int i, j; // Get the pre-existing indexes: int nclasses = tag_count[CONSTANT_Class]; @@ -3047,13 +3074,13 @@ void cpool::initMemberIndexes() { for (j = 0; j < nfields; j++) { entry& f = fields[j]; i = f.memberClass()->inord; - assert((uint)i < nclasses); + assert(i < nclasses); field_counts[i]++; } for (j = 0; j < nmethods; j++) { entry& m = methods[j]; i = m.memberClass()->inord; - assert((uint)i < nclasses); + assert(i < nclasses); method_counts[i]++; } @@ -3068,8 +3095,8 @@ void cpool::initMemberIndexes() { // reuse field_counts and member_counts as fill pointers: field_counts[i] = fbase; method_counts[i] = mbase; - printcr(3, "class %d fields @%d[%d] methods @%d[%d]", - i, fbase, fc, mbase, mc); + PRINTCR((3, "class %d fields @%d[%d] methods @%d[%d]", + i, fbase, fc, mbase, mc)); fbase += fc+1; mbase += mc+1; // (the +1 leaves a space between every subarray) @@ -3093,18 +3120,18 @@ void cpool::initMemberIndexes() { #ifndef PRODUCT // Test the result immediately on every class and field. int fvisited = 0, mvisited = 0; - int prevord; + int prevord, len; for (i = 0; i < nclasses; i++) { entry* cls = &classes[i]; cpindex* fix = getFieldIndex(cls); cpindex* mix = getMethodIndex(cls); - printcr(2, "field and method index for %s [%d] [%d]", - cls->string(), mix->len, fix->len); + PRINTCR((2, "field and method index for %s [%d] [%d]", + cls->string(), mix->len, fix->len)); prevord = -1; for (j = 0, len = fix->len; j < len; j++) { entry* f = fix->get(j); assert(f != null); - printcr(3, "- field %s", f->string()); + PRINTCR((3, "- field %s", f->string())); assert(f->memberClass() == cls); assert(prevord < (int)f->inord); prevord = f->inord; @@ -3115,7 +3142,7 @@ void cpool::initMemberIndexes() { for (j = 0, len = mix->len; j < len; j++) { entry* m = mix->get(j); assert(m != null); - printcr(3, "- method %s", m->string()); + PRINTCR((3, "- method %s", m->string())); assert(m->memberClass() == cls); assert(prevord < (int)m->inord); prevord = m->inord; @@ -3164,7 +3191,7 @@ void cpool::resetOutputIndexes() { outputEntries.empty(); #ifndef PRODUCT // they must all be clear now - for (i = 0; i < nentries; i++) + for (i = 0; i < (int)nentries; i++) assert(entries[i].outputIndex == NOT_REQUESTED); #endif } @@ -3215,7 +3242,7 @@ void cpool::computeOutputIndexes() { static uint checkStart = 0; int checkStep = 1; if (nentries > 100) checkStep = nentries / 100; - for (i = (checkStart++ % checkStep); i < nentries; i += checkStep) { + for (i = (int)(checkStart++ % checkStep); i < (int)nentries; i += checkStep) { entry& e = entries[i]; if (e.outputIndex != NOT_REQUESTED) { assert(outputEntries.contains(&e)); @@ -3225,7 +3252,7 @@ void cpool::computeOutputIndexes() { } // check hand-initialization of TAG_ORDER - for (i = 0; i < N_TAGS_IN_ORDER; i++) { + for (i = 0; i < (int)N_TAGS_IN_ORDER; i++) { byte tag = TAGS_IN_ORDER[i]; assert(TAG_ORDER[tag] == i+1); } @@ -3247,7 +3274,7 @@ void cpool::computeOutputIndexes() { if (e.isDoubleWord()) nextIndex++; // do not use the next index } outputIndexLimit = nextIndex; - printcr(3,"renumbering CP to %d entries", outputIndexLimit); + PRINTCR((3,"renumbering CP to %d entries", outputIndexLimit)); } #ifndef PRODUCT @@ -3257,9 +3284,9 @@ unpacker* debug_u; static bytes& getbuf(int len) { // for debugging only! static int bn = 0; - static bytes bufs[8] = { 0 }; + static bytes bufs[8]; bytes& buf = bufs[bn++ & 7]; - while (buf.len < len+10) + while ((int)buf.len < len+10) buf.realloc(buf.len ? buf.len * 2 : 1000); buf.ptr[0] = 0; // for the sake of strcat return buf; @@ -3285,7 +3312,7 @@ char* entry::string() { case CONSTANT_Long: case CONSTANT_Double: buf = getbuf(24); - sprintf((char*)buf.ptr, "0x%016llx", value.l); + sprintf((char*)buf.ptr, "0x" LONG_LONG_HEX_FORMAT, value.l); break; default: if (nrefs == 0) { @@ -3296,7 +3323,7 @@ char* entry::string() { } else { char* s1 = refs[0]->string(); char* s2 = refs[1]->string(); - buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1); + buf = getbuf((int)strlen(s1) + 1 + (int)strlen(s2) + 4 + 1); buf.strcat(s1).strcat(" ").strcat(s2); if (nrefs > 2) buf.strcat(" ..."); } @@ -3409,7 +3436,9 @@ void unpacker::reset() { segments_read_before_reset += 1; if (verbose >= 2) { fprintf(errstrm, - "After segment %d, %lld bytes read and %lld bytes written.\n", + "After segment %d, " + LONG_LONG_FORMAT " bytes read and " + LONG_LONG_FORMAT " bytes written.\n", segments_read_before_reset-1, bytes_read_before_reset, bytes_written_before_reset); fprintf(errstrm, @@ -3475,7 +3504,9 @@ void unpacker::init(read_input_fn_t input_fn) { int i; NOT_PRODUCT(debug_u = this); BYTES_OF(*this).clear(); - if (assert(1)) free(); // just to make sure freeing is idempotent +#ifndef PRODUCT + free(); // just to make sure freeing is idempotent +#endif this->u = this; // self-reference for U_NEW macro errstrm = stdout; // default error-output log_file = LOGFILE_STDOUT; @@ -3621,7 +3652,7 @@ void unpacker::put_stackmap_type() { maybe_inline void unpacker::put_label(int curIP, int size) { code_fixup_type.addByte(size); - code_fixup_offset.add(put_empty(size)); + code_fixup_offset.add((int)put_empty(size)); code_fixup_source.add(curIP); } @@ -3658,7 +3689,7 @@ void unpacker::write_bc_ops() { } for (int curIP = 0; ; curIP++) { - int curPC = wpoffset() - codeBase; + int curPC = (int)(wpoffset() - codeBase); bcimap.add(curPC); ensure_put_space(10); // covers most instrs w/o further bounds check int bc = *opptr++ & 0xFF; @@ -3702,7 +3733,7 @@ void unpacker::write_bc_ops() { put_label(curIP, 4); //int lVal = bc_label.getInt(); } } - assert(to_bci(curIP) == curPC); + assert((int)to_bci(curIP) == curPC); continue; } case bc_iinc: @@ -3805,7 +3836,7 @@ void unpacker::write_bc_ops() { assert(bc <= bc_jsr_w); put_label(curIP, 4); //putu4(lVal); } - assert(to_bci(curIP) == curPC); + assert((int)to_bci(curIP) == curPC); continue; } bc_which = ref_band_for_op(bc); @@ -3880,7 +3911,7 @@ void unpacker::write_bc_ops() { //bcimap.add(curPC); // PC limit is already also in map, from bc_end_marker // Armed with a bcimap, we can now fix up all the labels. - for (int i = 0; i < code_fixup_type.size(); i++) { + for (int i = 0; i < (int)code_fixup_type.size(); i++) { int type = code_fixup_type.getByte(i); byte* bp = wp_at(code_fixup_offset.get(i)); int curIP = code_fixup_source.get(i); @@ -3896,7 +3927,7 @@ void unpacker::write_bc_ops() { inline // called exactly once => inline void unpacker::write_code() { - int i, j; + int j; int max_stack, max_locals, handler_count, cflags; get_code_header(max_stack, max_locals, handler_count, cflags); @@ -3919,7 +3950,7 @@ void unpacker::write_code() { CHECK; byte* bcbasewp = wp_at(bcbase); - putu4_at(bcbasewp, wp - (bcbasewp+4)); // size of code attr + putu4_at(bcbasewp, (int)(wp - (bcbasewp+4))); // size of code attr putu2(handler_count); for (j = 0; j < handler_count; j++) { @@ -3968,10 +3999,10 @@ int unpacker::write_attrs(int attrc, julong indexBits) { if ((indexBits & 1) != 0) bitIndexes[biCount++] = idx; } - assert(biCount <= lengthof(bitIndexes)); + assert(biCount <= (int)lengthof(bitIndexes)); // Write a provisional attribute count, perhaps to be corrected later. - int naOffset = wpoffset(); + int naOffset = (int)wpoffset(); int na0 = biCount + oiCount; putu2(na0); @@ -3986,7 +4017,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) { entry* ref; // scratch size_t abase = put_empty(2+4); CHECK_0; - if (idx < ad.flag_limit && ad.isPredefined(idx)) { + if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) { // Switch on the attrc and idx simultaneously. switch (ADH_BYTE(attrc, idx)) { @@ -4020,16 +4051,16 @@ int unpacker::write_attrs(int attrc, julong indexBits) { if (ref == null) { bytes& n = cur_class->ref(0)->value.b; // parse n = (/)*?($)* - int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, n.len)+1; + int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, (int)n.len)+1; bytes prefix = n.slice(pkglen, n.len); for (;;) { // Work backwards, finding all '$', '#', etc. - int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, prefix.len); + int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len); if (dollar < 0) break; prefix = prefix.slice(0, dollar); } const char* suffix = ".java"; - int len = prefix.len + strlen(suffix); + int len = (int)(prefix.len + strlen(suffix)); bytes name; name.set(T_NEW(byte, len + 1), len); name.strcat(prefix).strcat(suffix); ref = cp.ensureUtf8(name); @@ -4081,7 +4112,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) { // (253) [(1)(2)(2)] // (254) [(1)(2)(2)(2)] putu2(code_StackMapTable_offset.getInt()); - for (int j2 = (tag - 251); j2 > 0; j2--) { + for (int k = (tag - 251); k > 0; k--) { put_stackmap_type(); } } else { @@ -4165,7 +4196,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) { abort("bad layout index"); break; } - assert(lo->idx == idx); + assert((int)lo->idx == idx); aname = lo->nameEntry; if (aname == null) { bytes nameb; nameb.set(lo->name); @@ -4198,7 +4229,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) { // patch the name and length putref(aname); - putu4(wp1 - (wp+4)); // put the attr size + putu4((int)(wp1 - (wp+4))); // put the attr size wp = wp1; na++; // count the attrs actually written } @@ -4279,7 +4310,7 @@ void unpacker::write_classfile_tail() { cur_class_has_local_ics = false; // may be set true by write_attrs - int naOffset = wpoffset(); + int naOffset = (int)wpoffset(); int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask)); @@ -4448,7 +4479,7 @@ void unpacker::write_classfile_head() { putu1(tag); switch (tag) { case CONSTANT_Utf8: - putu2(e.value.b.len); + putu2((int)e.value.b.len); put_bytes(e.value.b); break; case CONSTANT_Integer: @@ -4479,7 +4510,7 @@ void unpacker::write_classfile_head() { #ifndef PRODUCT total_cp_size[0] += cp.outputIndexLimit; - total_cp_size[1] += cur_classfile_head.size(); + total_cp_size[1] += (int)cur_classfile_head.size(); #endif close_output(); } @@ -4544,7 +4575,7 @@ unpacker::file* unpacker::get_next_file() { if (cur_file.name[0] == '\0') { bytes& prefix = cur_class->ref(0)->value.b; const char* suffix = ".class"; - int len = prefix.len + strlen(suffix); + int len = (int)(prefix.len + strlen(suffix)); bytes name; name.set(T_NEW(byte, len + 1), len); cur_file.name = name.strcat(prefix).strcat(suffix).strval(); } @@ -4564,7 +4595,7 @@ unpacker::file* unpacker::get_next_file() { } if (rpleft < cur_file.size) { // Caller must read the rest. - size_t fleft = cur_file.size - rpleft; + size_t fleft = (size_t)cur_file.size - rpleft; bytes_read += fleft; // Credit it to the overall archive size. } } @@ -4580,7 +4611,7 @@ void unpacker::write_file_to_jar(unpacker::file* f) { julong fsize = f->size; #ifndef PRODUCT if (nowrite NOT_PRODUCT(|| skipfiles-- > 0)) { - printcr(2,"would write %d bytes to %s", (int) fsize, f->name); + PRINTCR((2,"would write %d bytes to %s", (int) fsize, f->name)); return; } #endif @@ -4623,7 +4654,8 @@ void unpacker::write_file_to_jar(unpacker::file* f) { part1, part2); } if (verbose >= 3) { - fprintf(errstrm, "Wrote %lld bytes to: %s\n", fsize, f->name); + fprintf(errstrm, "Wrote " + LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name); } } diff --git a/src/share/native/com/sun/java/util/jar/pack/unpack.h b/src/share/native/com/sun/java/util/jar/pack/unpack.h index 7ab8e07b2..8bad674e0 100644 --- a/src/share/native/com/sun/java/util/jar/pack/unpack.h +++ b/src/share/native/com/sun/java/util/jar/pack/unpack.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -314,7 +314,7 @@ struct unpacker { void readBandData(band** body, uint count); // recursive helper layout_definition* getLayout(uint idx) { - if (idx >= layouts.length()) return null; + if (idx >= (uint)layouts.length()) return null; return (layout_definition*) layouts.get(idx); } @@ -332,12 +332,12 @@ struct unpacker { int predefCount(uint idx); bool isRedefined(uint idx) { - assert(idx < flag_limit); - return ((redef >> idx) & 1); + if (idx >= flag_limit) return false; + return (bool)((redef >> idx) & 1); } bool isPredefined(uint idx) { - assert(idx < flag_limit); - return (((predef & ~redef) >> idx) & 1); + if (idx >= flag_limit) return false; + return (bool)(((predef & ~redef) >> idx) & 1); } julong flagIndexMask() { return (predef | redef); @@ -345,9 +345,9 @@ struct unpacker { bool isIndex(uint idx) { assert(flag_limit != 0); // must be set up already if (idx < flag_limit) - return (((predef | redef) >> idx) & 1); + return (bool)(((predef | redef) >> idx) & 1); else - return (idx - flag_limit < overflow_count.length()); + return (idx - flag_limit < (uint)overflow_count.length()); } int& getCount(uint idx) { assert(isIndex(idx)); diff --git a/src/share/native/com/sun/java/util/jar/pack/utils.cpp b/src/share/native/com/sun/java/util/jar/pack/utils.cpp index 4f45c84b5..9566e5412 100644 --- a/src/share/native/com/sun/java/util/jar/pack/utils.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,7 +65,7 @@ void* must_malloc(int size) { void mkdirs(int oklen, char* path) { - if (strlen(path) <= oklen) return; + if (strlen(path) <= (size_t)oklen) return; char dir[PATH_MAX]; strcpy(dir, path); @@ -79,12 +79,13 @@ void mkdirs(int oklen, char* path) { #ifndef PRODUCT void breakpoint() { } // hook for debugger -void assert_failed(const char* p) { +int assert_failed(const char* p) { char message[1<<12]; sprintf(message, "@assert failed: %s\n", p); fprintf(stdout, 1+message); breakpoint(); unpack_abort(message); + return 0; } #endif diff --git a/src/share/native/com/sun/java/util/jar/pack/utils.h b/src/share/native/com/sun/java/util/jar/pack/utils.h index 6176634bc..2fc1728d8 100644 --- a/src/share/native/com/sun/java/util/jar/pack/utils.h +++ b/src/share/native/com/sun/java/util/jar/pack/utils.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ void* must_malloc(int size); #ifndef USE_MTRACE -#define mtrace(c, ptr, size) (0) +#define mtrace(c, ptr, size) #else void mtrace(char c, void* ptr, size_t size); #endif diff --git a/src/share/native/com/sun/java/util/jar/pack/zip.cpp b/src/share/native/com/sun/java/util/jar/pack/zip.cpp index 1042738f2..6bfb64463 100644 --- a/src/share/native/com/sun/java/util/jar/pack/zip.cpp +++ b/src/share/native/com/sun/java/util/jar/pack/zip.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,7 +85,7 @@ void jar::init(unpacker* u_) { // Write data to the ZIP output stream. void jar::write_data(void* buff, int len) { while (len > 0) { - int rc = fwrite(buff, 1, len, jarfp); + int rc = (int)fwrite(buff, 1, len, jarfp); if (rc <= 0) { fprintf(u->errstrm, "Error: write on output file failed err=%d\n",errno); exit(1); // Called only from the native standalone unpacker @@ -98,17 +98,17 @@ void jar::write_data(void* buff, int len) { void jar::add_to_jar_directory(const char* fname, bool store, int modtime, int len, int clen, uLong crc) { - uint fname_length = strlen(fname); + uint fname_length = (uint)strlen(fname); ushort header[23]; if (modtime == 0) modtime = default_modtime; uLong dostime = get_dostime(modtime); - header[0] = SWAP_BYTES(0x4B50); - header[1] = SWAP_BYTES(0x0201); - header[2] = SWAP_BYTES(0xA); + header[0] = (ushort)SWAP_BYTES(0x4B50); + header[1] = (ushort)SWAP_BYTES(0x0201); + header[2] = (ushort)SWAP_BYTES(0xA); // required version - header[3] = SWAP_BYTES(0xA); + header[3] = (ushort)SWAP_BYTES(0xA); // flags 02 = maximum sub-compression flag header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x2); @@ -117,23 +117,23 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, header[5] = ( store ) ? 0x0 : SWAP_BYTES(0x08); // Last modified date and time. - header[6] = GET_INT_LO(dostime); - header[7] = GET_INT_HI(dostime); + header[6] = (ushort)GET_INT_LO(dostime); + header[7] = (ushort)GET_INT_HI(dostime); // CRC - header[8] = GET_INT_LO(crc); - header[9] = GET_INT_HI(crc); + header[8] = (ushort)GET_INT_LO(crc); + header[9] = (ushort)GET_INT_HI(crc); // Compressed length: - header[10] = GET_INT_LO(clen); - header[11] = GET_INT_HI(clen); + header[10] = (ushort)GET_INT_LO(clen); + header[11] = (ushort)GET_INT_HI(clen); // Uncompressed length. - header[12] = GET_INT_LO(len); - header[13] = GET_INT_HI(len); + header[12] = (ushort)GET_INT_LO(len); + header[13] = (ushort)GET_INT_HI(len); // Filename length - header[14] = SWAP_BYTES(fname_length); + header[14] = (ushort)SWAP_BYTES(fname_length); // So called "extra field" length. header[15] = 0; // So called "comment" length. @@ -146,8 +146,8 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, header[19] = 0; header[20] = 0; // Offset within ZIP file. - header[21] = GET_INT_LO(output_file_offset); - header[22] = GET_INT_HI(output_file_offset); + header[21] = (ushort)GET_INT_LO(output_file_offset); + header[22] = (ushort)GET_INT_HI(output_file_offset); // Copy the whole thing into the central directory. central_directory.append(header, sizeof(header)); @@ -160,17 +160,17 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, void jar::write_jar_header(const char* fname, bool store, int modtime, int len, int clen, uint crc) { - uint fname_length = strlen(fname); + uint fname_length = (uint)strlen(fname); ushort header[15]; if (modtime == 0) modtime = default_modtime; uLong dostime = get_dostime(modtime); // ZIP LOC magic. - header[0] = SWAP_BYTES(0x4B50); - header[1] = SWAP_BYTES(0x0403); + header[0] = (ushort)SWAP_BYTES(0x4B50); + header[1] = (ushort)SWAP_BYTES(0x0403); // Version - header[2] = SWAP_BYTES(0xA); + header[2] = (ushort)SWAP_BYTES(0xA); // flags 02 = maximum sub-compression flag header[3] = ( store ) ? 0x0 : SWAP_BYTES(0x2); @@ -179,31 +179,31 @@ void jar::write_jar_header(const char* fname, bool store, int modtime, header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x08); // Last modified date and time. - header[5] = GET_INT_LO(dostime); - header[6] = GET_INT_HI(dostime); + header[5] = (ushort)GET_INT_LO(dostime); + header[6] = (ushort)GET_INT_HI(dostime); // CRC - header[7] = GET_INT_LO(crc); - header[8] = GET_INT_HI(crc); + header[7] = (ushort)GET_INT_LO(crc); + header[8] = (ushort)GET_INT_HI(crc); // Compressed length: - header[9] = GET_INT_LO(clen); - header[10] = GET_INT_HI(clen); + header[9] = (ushort)GET_INT_LO(clen); + header[10] = (ushort)GET_INT_HI(clen); // Uncompressed length. - header[11] = GET_INT_LO(len); - header[12] = GET_INT_HI(len); + header[11] = (ushort)GET_INT_LO(len); + header[12] = (ushort)GET_INT_HI(len); // Filename length - header[13] = SWAP_BYTES(fname_length); + header[13] = (ushort)SWAP_BYTES(fname_length); // So called "extra field" length. header[14] = 0; // Write the LOC header to the output file. - write_data(header, sizeof(header)); + write_data(header, (int)sizeof(header)); // Copy the fname to the header. - write_data((char*)fname, fname_length); + write_data((char*)fname, (int)fname_length); } static const char marker_comment[] = ZIP_ARCHIVE_MARKER_COMMENT; @@ -214,32 +214,32 @@ void jar::write_central_directory() { ushort header[11]; // Create the End of Central Directory structure. - header[0] = SWAP_BYTES(0x4B50); - header[1] = SWAP_BYTES(0x0605); + header[0] = (ushort)SWAP_BYTES(0x4B50); + header[1] = (ushort)SWAP_BYTES(0x0605); // disk numbers header[2] = 0; header[3] = 0; // Number of entries in central directory. - header[4] = SWAP_BYTES(central_directory_count); - header[5] = SWAP_BYTES(central_directory_count); + header[4] = (ushort)SWAP_BYTES(central_directory_count); + header[5] = (ushort)SWAP_BYTES(central_directory_count); // Size of the central directory} - header[6] = GET_INT_LO(central_directory.size()); - header[7] = GET_INT_HI(central_directory.size()); + header[6] = (ushort)GET_INT_LO((int)central_directory.size()); + header[7] = (ushort)GET_INT_HI((int)central_directory.size()); // Offset of central directory within disk. - header[8] = GET_INT_LO(output_file_offset); - header[9] = GET_INT_HI(output_file_offset); + header[8] = (ushort)GET_INT_LO(output_file_offset); + header[9] = (ushort)GET_INT_HI(output_file_offset); // zipfile comment length; - header [10] = SWAP_BYTES(mc.len); + header [10] = (ushort)SWAP_BYTES((int)mc.len); // Write the central directory. - printcr(2, "Central directory at %d\n", output_file_offset); + PRINTCR((2, "Central directory at %d\n", output_file_offset)); write_data(central_directory.b); // Write the End of Central Directory structure. - printcr(2, "end-of-directory at %d\n", output_file_offset); - write_data(header, sizeof(header)); + PRINTCR((2, "end-of-directory at %d\n", output_file_offset)); + write_data(header, (int)sizeof(header)); - printcr(2, "writing zip comment\n"); + PRINTCR((2, "writing zip comment\n")); // Write the comment. write_data(mc); } @@ -249,7 +249,7 @@ void jar::write_central_directory() { // Open a Jar file and initialize. void jar::openJarFile(const char* fname) { if (!jarfp) { - printcr(1, "jar::openJarFile: opening %s\n",fname); + PRINTCR((1, "jar::openJarFile: opening %s\n",fname)); jarfp = fopen(fname, "wb"); if (!jarfp) { fprintf(u->errstrm, "Error: Could not open jar file: %s\n",fname); @@ -262,25 +262,25 @@ void jar::openJarFile(const char* fname) { void jar::addJarEntry(const char* fname, bool deflate_hint, int modtime, bytes& head, bytes& tail) { - int len = head.len + tail.len; + int len = (int)(head.len + tail.len); int clen = 0; - uint crc = get_crc32(0L,Z_NULL,0); + uint crc = get_crc32(0,Z_NULL,0); if (head.len != 0) - crc = get_crc32(crc, (uchar *)head.ptr, head.len); + crc = get_crc32(crc, (uchar *)head.ptr, (uint)head.len); if (tail.len != 0) - crc = get_crc32(crc, (uchar *)tail.ptr, tail.len); + crc = get_crc32(crc, (uchar *)tail.ptr, (uint)tail.len); bool deflate = (deflate_hint && len > 0); if (deflate) { if (deflate_bytes(head, tail) == false) { - printcr(2, "Reverting to store fn=%s\t%d -> %d\n", - fname, len, deflated.size()); + PRINTCR((2, "Reverting to store fn=%s\t%d -> %d\n", + fname, len, deflated.size())); deflate = false; } } - clen = (deflate) ? deflated.size() : len; + clen = (int)((deflate) ? deflated.size() : len); add_to_jar_directory(fname, !deflate, modtime, len, clen, crc); write_jar_header( fname, !deflate, modtime, len, clen, crc); @@ -306,7 +306,7 @@ void jar::closeJarFile(bool central) { if (central) write_central_directory(); fflush(jarfp); fclose(jarfp); - printcr(2, "jar::closeJarFile:closed jar-file\n"); + PRINTCR((2, "jar::closeJarFile:closed jar-file\n")); } reset(); } @@ -338,6 +338,7 @@ uLong jar::get_dostime(int modtime) { default_modtime = modtime; // catch a reasonable default time_t t = modtime; struct tm sbuf; + (void)memset((void*)&sbuf,0, sizeof(sbuf)); struct tm* s = gmtime_r(&t, &sbuf); modtime_cache = modtime; dostime_cache = dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday, @@ -355,7 +356,7 @@ uLong jar::get_dostime(int modtime) { input data */ bool jar::deflate_bytes(bytes& head, bytes& tail) { - int len = head.len + tail.len; + int len = (int)(head.len + tail.len); z_stream zs; BYTES_OF(zs).clear(); @@ -368,26 +369,26 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) { if (error != Z_OK) { switch (error) { case Z_MEM_ERROR: - printcr(2, "Error: deflate error : Out of memory \n"); + PRINTCR((2, "Error: deflate error : Out of memory \n")); break; case Z_STREAM_ERROR: - printcr(2,"Error: deflate error : Invalid compression level \n"); + PRINTCR((2,"Error: deflate error : Invalid compression level \n")); break; case Z_VERSION_ERROR: - printcr(2,"Error: deflate error : Invalid version\n"); + PRINTCR((2,"Error: deflate error : Invalid version\n")); break; default: - printcr(2,"Error: Internal deflate error error = %d\n", error); + PRINTCR((2,"Error: Internal deflate error error = %d\n", error)); } return false; } deflated.empty(); zs.next_out = (uchar*) deflated.grow(len + (len/2)); - zs.avail_out = deflated.size(); + zs.avail_out = (int)deflated.size(); zs.next_in = (uchar*)head.ptr; - zs.avail_in = head.len; + zs.avail_in = (int)head.len; bytes* first = &head; bytes* last = &tail; @@ -400,28 +401,28 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) { if (first != null && error == Z_OK) { zs.next_in = (uchar*) first->ptr; - zs.avail_in = first->len; + zs.avail_in = (int)first->len; error = deflate(&zs, Z_NO_FLUSH); } if (error == Z_OK) { zs.next_in = (uchar*) last->ptr; - zs.avail_in = last->len; + zs.avail_in = (int)last->len; error = deflate(&zs, Z_FINISH); } if (error == Z_STREAM_END) { - if (len > zs.total_out ) { - printcr(2, "deflate compressed data %d -> %d\n", len, zs.total_out); + if (len > (int)zs.total_out ) { + PRINTCR((2, "deflate compressed data %d -> %d\n", len, zs.total_out)); deflated.b.len = zs.total_out; deflateEnd(&zs); return true; } - printcr(2, "deflate expanded data %d -> %d\n", len, zs.total_out); + PRINTCR((2, "deflate expanded data %d -> %d\n", len, zs.total_out)); deflateEnd(&zs); return false; } deflateEnd(&zs); - printcr(2, "Error: deflate error deflate did not finish error=%d\n",error); + PRINTCR((2, "Error: deflate error deflate did not finish error=%d\n",error)); return false; } @@ -486,7 +487,7 @@ void gunzip::init(unpacker* u_) { BYTES_OF(*this).clear(); u = u_; assert(u->gzin == null); // once only, please - read_input_fn = (void*)(intptr_t)u->read_input_fn; + read_input_fn = (void*)u->read_input_fn; zstream = NEW(z_stream, 1); u->gzin = this; u->read_input_fn = read_input_via_gzip; @@ -555,7 +556,7 @@ void gunzip::read_fixed_field(char* buf, size_t buflen) { if (aborting()) return; jlong nr = ((unpacker::read_input_fn_t)read_input_fn) (u, buf, buflen, buflen); - if (nr != buflen) + if ((size_t)nr != buflen) u->abort("short stream header"); } diff --git a/src/share/native/com/sun/java/util/jar/pack/zip.h b/src/share/native/com/sun/java/util/jar/pack/zip.h index 358dbe51f..007dfc3f7 100644 --- a/src/share/native/com/sun/java/util/jar/pack/zip.h +++ b/src/share/native/com/sun/java/util/jar/pack/zip.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -69,7 +69,7 @@ struct jar { // Private Methods void write_data(void* ptr, int len); - void write_data(bytes& b) { write_data(b.ptr, b.len); } + void write_data(bytes& b) { write_data(b.ptr, (int)b.len); } void add_to_jar_directory(const char* fname, bool store, int modtime, int len, int clen, uLong crc); void write_jar_header(const char* fname, bool store, int modtime, -- GitLab