提交 8e36b5da 编写于 作者: O ohair

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
上级 4b3d5938
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -126,15 +126,15 @@ void band::readData(int expectedLength) { ...@@ -126,15 +126,15 @@ void band::readData(int expectedLength) {
(*save_meta_rp) = (byte) XB; (*save_meta_rp) = (byte) XB;
cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null); 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 (*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; rplimit = u->rp;
rewind(); rewind();
#ifndef PRODUCT #ifndef PRODUCT
printcr(3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]", PRINTCR((3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]",
(name?name:"(band)"), minRP(), length, size(), cp1, cp2); (name?name:"(band)"), minRP(), length, size(), cp1, cp2));
if (u->verbose_bands || u->verbose >= 4) dump(); if (u->verbose_bands || u->verbose >= 4) dump();
if (ix != null && u->verbose != 0 && length > 0) { if (ix != null && u->verbose != 0 && length > 0) {
...@@ -421,18 +421,22 @@ const band_init all_band_inits[] = { ...@@ -421,18 +421,22 @@ const band_init all_band_inits[] = {
BAND_INIT(file_modtime, DELTA5_spec, 0), BAND_INIT(file_modtime, DELTA5_spec, 0),
BAND_INIT(file_options, UNSIGNED5_spec, 0), BAND_INIT(file_options, UNSIGNED5_spec, 0),
//BAND_INIT(file_bits, BYTE1_spec, 0), //BAND_INIT(file_bits, BYTE1_spec, 0),
{0} #ifndef PRODUCT
{ 0, 0, 0, 0 }
#else
{ 0, 0 }
#endif
}; };
#define NUM_BAND_INITS \ #define NUM_BAND_INITS \
(sizeof(all_band_inits)/sizeof(all_band_inits[0])) (sizeof(all_band_inits)/sizeof(all_band_inits[0]))
band* band::makeBands(unpacker* u) { 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++) { for (int i = 0; i < BAND_LIMIT; i++) {
assert((byte*)&all_band_inits[i+1] assert((byte*)&all_band_inits[i+1]
< (byte*)all_band_inits+sizeof(all_band_inits)); < (byte*)all_band_inits+sizeof(all_band_inits));
const band_init& bi = all_band_inits[i]; 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); coding* defc = coding::findBySpec(bi.defc);
assert((defc == null) == (bi.defc == -1)); // no garbage, please assert((defc == null) == (bi.defc == -1)); // no garbage, please
assert(defc == null || !defc->isMalloc); assert(defc == null || !defc->isMalloc);
...@@ -446,13 +450,13 @@ band* band::makeBands(unpacker* u) { ...@@ -446,13 +450,13 @@ band* band::makeBands(unpacker* u) {
b.name = bi.name; b.name = bi.name;
#endif #endif
} }
return all_bands; return tmp_all_bands;
} }
void band::initIndexes(unpacker* u) { 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++) { 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 uint tag = scan->ixTag; // Cf. #define INDEX(tag) above
if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) { if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) {
scan->setIndex(u->cp.getIndex(tag)); scan->setIndex(u->cp.getIndex(tag));
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -71,15 +71,17 @@ void bytes::realloc(size_t len_) { ...@@ -71,15 +71,17 @@ void bytes::realloc(size_t len_) {
void bytes::free() { void bytes::free() {
if (ptr == dummy) return; // escaping from an error if (ptr == dummy) return; // escaping from an error
if (ptr != null) mtrace('f', ptr, 0); if (ptr != null) {
if (ptr != null) ::free(ptr); mtrace('f', ptr, 0);
::free(ptr);
}
len = 0; len = 0;
ptr = 0; ptr = 0;
} }
int bytes::indexOf(byte c) { int bytes::indexOf(byte c) {
byte* p = (byte*) memchr(ptr, c, len); 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) { byte* bytes::writeTo(byte* bp) {
...@@ -174,8 +176,10 @@ void ptrlist::freeAll() { ...@@ -174,8 +176,10 @@ void ptrlist::freeAll() {
int len = length(); int len = length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
void* p = (void*) get(i); void* p = (void*) get(i);
if (p != null) mtrace('f', p, 0); if (p != null) {
if (p != null) ::free(p); mtrace('f', p, 0);
::free(p);
}
} }
free(); free();
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -117,7 +117,7 @@ struct fillbytes { ...@@ -117,7 +117,7 @@ struct fillbytes {
struct ptrlist : fillbytes { struct ptrlist : fillbytes {
typedef const void* cvptr; typedef const void* cvptr;
int length() { return size() / sizeof(cvptr); } int length() { return (int)(size() / sizeof(cvptr)); }
cvptr* base() { return (cvptr*) fillbytes::base(); } cvptr* base() { return (cvptr*) fillbytes::base(); }
cvptr& get(int i) { return *(cvptr*)loc(i * sizeof(cvptr)); } cvptr& get(int i) { return *(cvptr*)loc(i * sizeof(cvptr)); }
cvptr* limit() { return (cvptr*) fillbytes::limit(); } cvptr* limit() { return (cvptr*) fillbytes::limit(); }
...@@ -133,7 +133,7 @@ struct ptrlist : fillbytes { ...@@ -133,7 +133,7 @@ struct ptrlist : fillbytes {
::qsort((ptrls).base(), (ptrls).length(), sizeof(void*), fn) ::qsort((ptrls).base(), (ptrls).length(), sizeof(void*), fn)
struct intlist : fillbytes { struct intlist : fillbytes {
int length() { return size() / sizeof(int); } int length() { return (int)(size() / sizeof(int)); }
int* base() { return (int*) fillbytes::base(); } int* base() { return (int*) fillbytes::base(); }
int& get(int i) { return *(int*)loc(i * sizeof(int)); } int& get(int i) { return *(int*)loc(i * sizeof(int)); }
int* limit() { return (int*) fillbytes::limit(); } int* limit() { return (int*) fillbytes::limit(); }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -113,7 +113,7 @@ coding* coding::init() { ...@@ -113,7 +113,7 @@ coding* coding::init() {
jlong maxNegCode = range-1; jlong maxNegCode = range-1;
while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode; while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode;
while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode; while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode;
int maxPos = decode_sign(S, maxPosCode); int maxPos = decode_sign(S, (uint)maxPosCode);
if (maxPos < 0) if (maxPos < 0)
this->max = INT_MAX_VALUE; // 32-bit wraparound this->max = INT_MAX_VALUE; // 32-bit wraparound
else else
...@@ -121,7 +121,7 @@ coding* coding::init() { ...@@ -121,7 +121,7 @@ coding* coding::init() {
if (maxNegCode < 0) if (maxNegCode < 0)
this->min = 0; // No negative codings at all. this->min = 0; // No negative codings at all.
else else
this->min = decode_sign(S, maxNegCode); this->min = decode_sign(S, (uint)maxNegCode);
} }
} }
...@@ -149,10 +149,10 @@ coding* coding::findBySpec(int spec) { ...@@ -149,10 +149,10 @@ coding* coding::findBySpec(int spec) {
coding* ptr = NEW(coding, 1); coding* ptr = NEW(coding, 1);
CHECK_NULL_0(ptr); CHECK_NULL_0(ptr);
coding* c = ptr->initFrom(spec); coding* c = ptr->initFrom(spec);
if (c == null) mtrace('f', ptr, 0); if (c == null) {
if (c == null) mtrace('f', ptr, 0);
::free(ptr); ::free(ptr);
else } else
// else caller should free it... // else caller should free it...
c->isMalloc = true; c->isMalloc = true;
return c; return c;
...@@ -167,9 +167,10 @@ coding* coding::findBySpec(int B, int H, int S, int D) { ...@@ -167,9 +167,10 @@ coding* coding::findBySpec(int B, int H, int S, int D) {
} }
void coding::free() { void coding::free() {
if (isMalloc) mtrace('f', this, 0); if (isMalloc) {
if (isMalloc) mtrace('f', this, 0);
::free(this); ::free(this);
}
} }
void coding_method::reset(value_stream* state) { void coding_method::reset(value_stream* state) {
...@@ -187,7 +188,7 @@ uint coding::parse(byte* &rp, int B, int H) { ...@@ -187,7 +188,7 @@ uint coding::parse(byte* &rp, int B, int H) {
byte* ptr = rp; byte* ptr = rp;
// hand peel the i==0 part of the loop: // hand peel the i==0 part of the loop:
uint b_i = *ptr++ & 0xFF; uint b_i = *ptr++ & 0xFF;
if (B == 1 || b_i < L) if (B == 1 || b_i < (uint)L)
{ rp = ptr; return b_i; } { rp = ptr; return b_i; }
uint sum = b_i; uint sum = b_i;
uint H_i = H; uint H_i = H;
...@@ -195,7 +196,7 @@ uint coding::parse(byte* &rp, int B, int 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 for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
b_i = *ptr++ & 0xFF; b_i = *ptr++ & 0xFF;
sum += b_i * H_i; sum += b_i * H_i;
if (i == B || b_i < L) if (i == B || b_i < (uint)L)
{ rp = ptr; return sum; } { rp = ptr; return sum; }
H_i *= H; H_i *= H;
} }
...@@ -210,7 +211,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) { ...@@ -210,7 +211,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) {
byte* ptr = rp; byte* ptr = rp;
// hand peel the i==0 part of the loop: // hand peel the i==0 part of the loop:
uint b_i = *ptr++ & 0xFF; uint b_i = *ptr++ & 0xFF;
if (B == 1 || b_i < L) if (B == 1 || b_i < (uint)L)
{ rp = ptr; return b_i; } { rp = ptr; return b_i; }
uint sum = b_i; uint sum = b_i;
uint lg_H_i = lgH; uint lg_H_i = lgH;
...@@ -218,7 +219,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int 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 for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
b_i = *ptr++ & 0xFF; b_i = *ptr++ & 0xFF;
sum += b_i << lg_H_i; sum += b_i << lg_H_i;
if (i == B || b_i < L) if (i == B || b_i < (uint)L)
{ rp = ptr; return sum; } { rp = ptr; return sum; }
lg_H_i += lgH; lg_H_i += lgH;
} }
...@@ -237,7 +238,7 @@ void coding::parseMultiple(byte* &rp, int N, byte* limit, int B, int H) { ...@@ -237,7 +238,7 @@ void coding::parseMultiple(byte* &rp, int N, byte* limit, int B, int H) {
byte* ptr = rp; byte* ptr = rp;
if (B == 1 || H == 256) { if (B == 1 || H == 256) {
size_t len = (size_t)N*B; 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); abort(ERB);
return; return;
} }
...@@ -325,7 +326,7 @@ static maybe_inline ...@@ -325,7 +326,7 @@ static maybe_inline
int getPopValue(value_stream* self, uint uval) { int getPopValue(value_stream* self, uint uval) {
if (uval > 0) { if (uval > 0) {
// note that the initial parse performed a range check // 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]; return self->cm->fValues[uval-1];
} else { } else {
// take an unfavored value // take an unfavored value
...@@ -368,7 +369,7 @@ int coding::sumInUnsignedRange(int x, int y) { ...@@ -368,7 +369,7 @@ int coding::sumInUnsignedRange(int x, int y) {
static maybe_inline static maybe_inline
int getDeltaValue(value_stream* self, uint uval, bool isSubrange) { 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); assert(self->c.isSubrange | self->c.isFullRange);
if (isSubrange) if (isSubrange)
return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval); return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval);
...@@ -443,7 +444,7 @@ int value_stream::getInt() { ...@@ -443,7 +444,7 @@ int value_stream::getInt() {
uval = coding::parse(rp, B, H); uval = coding::parse(rp, B, H);
if (S != 0) if (S != 0)
uval = (uint) decode_sign(S, uval); uval = (uint) decode_sign(S, uval);
return getDeltaValue(this, uval, c.isSubrange); return getDeltaValue(this, uval, (bool)c.isSubrange);
case cmk_BHS1D1full: case cmk_BHS1D1full:
assert(S == 1 && D == 1 && c.isFullRange); assert(S == 1 && D == 1 && c.isFullRange);
...@@ -499,6 +500,9 @@ int value_stream::getInt() { ...@@ -499,6 +500,9 @@ int value_stream::getInt() {
assert(c.spec == BYTE1_spec); assert(c.spec == BYTE1_spec);
assert(B == 1 && H == 256 && S == 0 && D == 0); assert(B == 1 && H == 256 && S == 0 && D == 0);
return getPopValue(this, *rp++ & 0xFF); return getPopValue(this, *rp++ & 0xFF);
default:
break;
} }
assert(false); assert(false);
return 0; return 0;
...@@ -695,7 +699,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit, ...@@ -695,7 +699,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit,
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
uint val = vs.getInt(); uint val = vs.getInt();
if (val == 0) UN += 1; if (val == 0) UN += 1;
if (!(val <= fVlength)) { if (!(val <= (uint)fVlength)) {
abort("pop token out of range"); abort("pop token out of range");
return; return;
} }
...@@ -728,6 +732,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit, ...@@ -728,6 +732,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit,
switch (self->vs0.cmk) { switch (self->vs0.cmk) {
case cmk_BHS0: cmk2 = cmk_pop_BHS0; break; case cmk_BHS0: cmk2 = cmk_pop_BHS0; break;
case cmk_BYTE1: cmk2 = cmk_pop_BYTE1; break; case cmk_BYTE1: cmk2 = cmk_pop_BYTE1; break;
default: break;
} }
self->vs0.cmk = cmk2; self->vs0.cmk = cmk2;
if (self != this) { if (self != this) {
...@@ -947,15 +952,17 @@ coding basic_codings[] = { ...@@ -947,15 +952,17 @@ coding basic_codings[] = {
CODING_INIT(4,240,1,1), CODING_INIT(4,240,1,1),
CODING_INIT(4,248,0,1), CODING_INIT(4,248,0,1),
CODING_INIT(4,248,1,1), CODING_INIT(4,248,1,1),
CODING_INIT(0,0,0,0)
0
}; };
#define BASIC_INDEX_LIMIT \ #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) { coding* coding::findByIndex(int idx) {
assert(_meta_canon_min == 1); #ifndef PRODUCT
assert(_meta_canon_max+1 == BASIC_INDEX_LIMIT); /* 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) if (idx >= _meta_canon_min && idx <= _meta_canon_max)
return basic_codings[idx].init(); return basic_codings[idx].init();
else else
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -35,9 +35,11 @@ struct unpacker; ...@@ -35,9 +35,11 @@ struct unpacker;
#define CODING_D(x) ((x)>>0 & 0xF) #define CODING_D(x) ((x)>>0 & 0xF)
#define CODING_INIT(B, H, S, D) \ #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 { struct coding {
int spec; // B,H,S,D int spec; // B,H,S,D
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,15 +45,15 @@ ...@@ -45,15 +45,15 @@
#ifdef PRODUCT #ifdef PRODUCT
#define IF_PRODUCT(xxx) xxx #define IF_PRODUCT(xxx) xxx
#define NOT_PRODUCT(xxx) #define NOT_PRODUCT(xxx)
#define assert(p) (0) #define assert(p)
#define printcr false && #define PRINTCR(args)
#else #else
#define IF_PRODUCT(xxx) #define IF_PRODUCT(xxx)
#define NOT_PRODUCT(xxx) xxx #define NOT_PRODUCT(xxx) xxx
#define assert(p) ((p) || (assert_failed(#p), 1)) #define assert(p) ((p) || assert_failed(#p))
#define printcr u->verbose && u->printcr_if_verbose #define PRINTCR(args) u->verbose && u->printcr_if_verbose args
extern "C" void breakpoint(); extern "C" void breakpoint();
extern void assert_failed(const char*); extern int assert_failed(const char*);
#define BREAK (breakpoint()) #define BREAK (breakpoint())
#endif #endif
...@@ -79,7 +79,7 @@ extern void assert_failed(const char*); ...@@ -79,7 +79,7 @@ extern void assert_failed(const char*);
#define lengthof(array) (sizeof(array)/sizeof(array[0])) #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 U_NEW(T, n) (T*) u->alloc(sizeof(T)*(n))
#define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n)) #define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n))
...@@ -121,12 +121,12 @@ enum { false, true }; ...@@ -121,12 +121,12 @@ enum { false, true };
#define null (0) #define null (0)
#ifndef __sparc /* Must cast to void *, then size_t, then int. */
#define intptr_t jlong #define ptrlowbits(x) ((int)(size_t)(void*)(x))
#endif
#define ptrlowbits(x) ((int) (intptr_t)(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: // Keys used by Java:
#define UNPACK_DEFLATE_HINT "unpack.deflate.hint" #define UNPACK_DEFLATE_HINT "unpack.deflate.hint"
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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, ...@@ -59,7 +59,8 @@ static jlong read_input_via_jni(unpacker* self,
void* buf, jlong minlen, jlong maxlen); void* buf, jlong minlen, jlong maxlen);
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) { 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); //fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr);
if (uPtr == null) { if (uPtr == null) {
if (noCreate) return null; if (noCreate) return null;
...@@ -71,7 +72,7 @@ static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) { ...@@ -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); //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
uPtr->init(read_input_via_jni); uPtr->init(read_input_via_jni);
uPtr->jniobj = (void*) env->NewGlobalRef(pObj); 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 uPtr->jnienv = env; // keep refreshing this in case of MT access
return uPtr; return uPtr;
...@@ -150,7 +151,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj, ...@@ -150,7 +151,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj,
size_t buflen = 0; size_t buflen = 0;
if (pBuf != null) { if (pBuf != null) {
buf = env->GetDirectBufferAddress(pBuf); buf = env->GetDirectBufferAddress(pBuf);
buflen = env->GetDirectBufferCapacity(pBuf); buflen = (size_t)env->GetDirectBufferCapacity(pBuf);
if (buflen == 0) buf = null; if (buflen == 0) buf = null;
if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; } if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; }
if ((size_t)offset >= buflen) if ((size_t)offset >= buflen)
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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, ...@@ -86,13 +86,13 @@ static jlong read_input_via_stdio(unpacker* u,
readlen = (int)(maxlen - numread); readlen = (int)(maxlen - numread);
int nr = 0; int nr = 0;
if (u->infileptr != null) { if (u->infileptr != null) {
nr = fread(bufptr, 1, readlen, u->infileptr); nr = (int)fread(bufptr, 1, readlen, u->infileptr);
} else { } else {
#ifndef WIN32 #ifndef WIN32
// we prefer unbuffered inputs // we prefer unbuffered inputs
nr = read(u->infileno, bufptr, readlen); nr = (int)read(u->infileno, bufptr, readlen);
#else #else
nr = fread(bufptr, 1, readlen, stdin); nr = (int)fread(bufptr, 1, readlen, stdin);
#endif #endif
} }
if (nr <= 0) { if (nr <= 0) {
...@@ -279,7 +279,6 @@ int unpacker::run(int argc, char **argv) { ...@@ -279,7 +279,6 @@ int unpacker::run(int argc, char **argv) {
char** argbuf = init_args(argc, argv, envargc); char** argbuf = init_args(argc, argv, envargc);
char** arg0 = argbuf+envargc; char** arg0 = argbuf+envargc;
char** argp = argbuf; char** argp = argbuf;
int ach;
int verbose = 0; int verbose = 0;
char* logfile = null; char* logfile = null;
...@@ -370,7 +369,7 @@ int unpacker::run(int argc, char **argv) { ...@@ -370,7 +369,7 @@ int unpacker::run(int argc, char **argv) {
int magic; int magic;
// check for GZIP input // 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) { if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC) {
// Oops; must slap an input filter on this data. // Oops; must slap an input filter on this data.
setup_gzin(&u); setup_gzin(&u);
...@@ -397,8 +396,8 @@ int unpacker::run(int argc, char **argv) { ...@@ -397,8 +396,8 @@ int unpacker::run(int argc, char **argv) {
if (u.aborting()) break; if (u.aborting()) break;
// Peek ahead for more data. // Peek ahead for more data.
magic = read_magic(&u, peek, sizeof(peek)); magic = read_magic(&u, peek, (int)sizeof(peek));
if (magic != JAVA_PACKAGE_MAGIC) { if (magic != (int)JAVA_PACKAGE_MAGIC) {
if (magic != EOF_MAGIC) if (magic != EOF_MAGIC)
u.abort("garbage after end of pack archive"); u.abort("garbage after end of pack archive");
break; // all done break; // all done
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -314,7 +314,7 @@ struct unpacker { ...@@ -314,7 +314,7 @@ struct unpacker {
void readBandData(band** body, uint count); // recursive helper void readBandData(band** body, uint count); // recursive helper
layout_definition* getLayout(uint idx) { layout_definition* getLayout(uint idx) {
if (idx >= layouts.length()) return null; if (idx >= (uint)layouts.length()) return null;
return (layout_definition*) layouts.get(idx); return (layout_definition*) layouts.get(idx);
} }
...@@ -332,12 +332,12 @@ struct unpacker { ...@@ -332,12 +332,12 @@ struct unpacker {
int predefCount(uint idx); int predefCount(uint idx);
bool isRedefined(uint idx) { bool isRedefined(uint idx) {
assert(idx < flag_limit); if (idx >= flag_limit) return false;
return ((redef >> idx) & 1); return (bool)((redef >> idx) & 1);
} }
bool isPredefined(uint idx) { bool isPredefined(uint idx) {
assert(idx < flag_limit); if (idx >= flag_limit) return false;
return (((predef & ~redef) >> idx) & 1); return (bool)(((predef & ~redef) >> idx) & 1);
} }
julong flagIndexMask() { julong flagIndexMask() {
return (predef | redef); return (predef | redef);
...@@ -345,9 +345,9 @@ struct unpacker { ...@@ -345,9 +345,9 @@ struct unpacker {
bool isIndex(uint idx) { bool isIndex(uint idx) {
assert(flag_limit != 0); // must be set up already assert(flag_limit != 0); // must be set up already
if (idx < flag_limit) if (idx < flag_limit)
return (((predef | redef) >> idx) & 1); return (bool)(((predef | redef) >> idx) & 1);
else else
return (idx - flag_limit < overflow_count.length()); return (idx - flag_limit < (uint)overflow_count.length());
} }
int& getCount(uint idx) { int& getCount(uint idx) {
assert(isIndex(idx)); assert(isIndex(idx));
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -65,7 +65,7 @@ void* must_malloc(int size) { ...@@ -65,7 +65,7 @@ void* must_malloc(int size) {
void mkdirs(int oklen, char* path) { void mkdirs(int oklen, char* path) {
if (strlen(path) <= oklen) return; if (strlen(path) <= (size_t)oklen) return;
char dir[PATH_MAX]; char dir[PATH_MAX];
strcpy(dir, path); strcpy(dir, path);
...@@ -79,12 +79,13 @@ void mkdirs(int oklen, char* path) { ...@@ -79,12 +79,13 @@ void mkdirs(int oklen, char* path) {
#ifndef PRODUCT #ifndef PRODUCT
void breakpoint() { } // hook for debugger void breakpoint() { } // hook for debugger
void assert_failed(const char* p) { int assert_failed(const char* p) {
char message[1<<12]; char message[1<<12];
sprintf(message, "@assert failed: %s\n", p); sprintf(message, "@assert failed: %s\n", p);
fprintf(stdout, 1+message); fprintf(stdout, 1+message);
breakpoint(); breakpoint();
unpack_abort(message); unpack_abort(message);
return 0;
} }
#endif #endif
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
void* must_malloc(int size); void* must_malloc(int size);
#ifndef USE_MTRACE #ifndef USE_MTRACE
#define mtrace(c, ptr, size) (0) #define mtrace(c, ptr, size)
#else #else
void mtrace(char c, void* ptr, size_t size); void mtrace(char c, void* ptr, size_t size);
#endif #endif
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -85,7 +85,7 @@ void jar::init(unpacker* u_) { ...@@ -85,7 +85,7 @@ void jar::init(unpacker* u_) {
// Write data to the ZIP output stream. // Write data to the ZIP output stream.
void jar::write_data(void* buff, int len) { void jar::write_data(void* buff, int len) {
while (len > 0) { while (len > 0) {
int rc = fwrite(buff, 1, len, jarfp); int rc = (int)fwrite(buff, 1, len, jarfp);
if (rc <= 0) { if (rc <= 0) {
fprintf(u->errstrm, "Error: write on output file failed err=%d\n",errno); fprintf(u->errstrm, "Error: write on output file failed err=%d\n",errno);
exit(1); // Called only from the native standalone unpacker exit(1); // Called only from the native standalone unpacker
...@@ -98,17 +98,17 @@ void jar::write_data(void* buff, int len) { ...@@ -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, void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
int len, int clen, uLong crc) { int len, int clen, uLong crc) {
uint fname_length = strlen(fname); uint fname_length = (uint)strlen(fname);
ushort header[23]; ushort header[23];
if (modtime == 0) modtime = default_modtime; if (modtime == 0) modtime = default_modtime;
uLong dostime = get_dostime(modtime); uLong dostime = get_dostime(modtime);
header[0] = SWAP_BYTES(0x4B50); header[0] = (ushort)SWAP_BYTES(0x4B50);
header[1] = SWAP_BYTES(0x0201); header[1] = (ushort)SWAP_BYTES(0x0201);
header[2] = SWAP_BYTES(0xA); header[2] = (ushort)SWAP_BYTES(0xA);
// required version // required version
header[3] = SWAP_BYTES(0xA); header[3] = (ushort)SWAP_BYTES(0xA);
// flags 02 = maximum sub-compression flag // flags 02 = maximum sub-compression flag
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x2); header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
...@@ -117,23 +117,23 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, ...@@ -117,23 +117,23 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
header[5] = ( store ) ? 0x0 : SWAP_BYTES(0x08); header[5] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
// Last modified date and time. // Last modified date and time.
header[6] = GET_INT_LO(dostime); header[6] = (ushort)GET_INT_LO(dostime);
header[7] = GET_INT_HI(dostime); header[7] = (ushort)GET_INT_HI(dostime);
// CRC // CRC
header[8] = GET_INT_LO(crc); header[8] = (ushort)GET_INT_LO(crc);
header[9] = GET_INT_HI(crc); header[9] = (ushort)GET_INT_HI(crc);
// Compressed length: // Compressed length:
header[10] = GET_INT_LO(clen); header[10] = (ushort)GET_INT_LO(clen);
header[11] = GET_INT_HI(clen); header[11] = (ushort)GET_INT_HI(clen);
// Uncompressed length. // Uncompressed length.
header[12] = GET_INT_LO(len); header[12] = (ushort)GET_INT_LO(len);
header[13] = GET_INT_HI(len); header[13] = (ushort)GET_INT_HI(len);
// Filename length // Filename length
header[14] = SWAP_BYTES(fname_length); header[14] = (ushort)SWAP_BYTES(fname_length);
// So called "extra field" length. // So called "extra field" length.
header[15] = 0; header[15] = 0;
// So called "comment" length. // So called "comment" length.
...@@ -146,8 +146,8 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, ...@@ -146,8 +146,8 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
header[19] = 0; header[19] = 0;
header[20] = 0; header[20] = 0;
// Offset within ZIP file. // Offset within ZIP file.
header[21] = GET_INT_LO(output_file_offset); header[21] = (ushort)GET_INT_LO(output_file_offset);
header[22] = GET_INT_HI(output_file_offset); header[22] = (ushort)GET_INT_HI(output_file_offset);
// Copy the whole thing into the central directory. // Copy the whole thing into the central directory.
central_directory.append(header, sizeof(header)); central_directory.append(header, sizeof(header));
...@@ -160,17 +160,17 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime, ...@@ -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, void jar::write_jar_header(const char* fname, bool store, int modtime,
int len, int clen, uint crc) { int len, int clen, uint crc) {
uint fname_length = strlen(fname); uint fname_length = (uint)strlen(fname);
ushort header[15]; ushort header[15];
if (modtime == 0) modtime = default_modtime; if (modtime == 0) modtime = default_modtime;
uLong dostime = get_dostime(modtime); uLong dostime = get_dostime(modtime);
// ZIP LOC magic. // ZIP LOC magic.
header[0] = SWAP_BYTES(0x4B50); header[0] = (ushort)SWAP_BYTES(0x4B50);
header[1] = SWAP_BYTES(0x0403); header[1] = (ushort)SWAP_BYTES(0x0403);
// Version // Version
header[2] = SWAP_BYTES(0xA); header[2] = (ushort)SWAP_BYTES(0xA);
// flags 02 = maximum sub-compression flag // flags 02 = maximum sub-compression flag
header[3] = ( store ) ? 0x0 : SWAP_BYTES(0x2); header[3] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
...@@ -179,31 +179,31 @@ void jar::write_jar_header(const char* fname, bool store, int modtime, ...@@ -179,31 +179,31 @@ void jar::write_jar_header(const char* fname, bool store, int modtime,
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x08); header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
// Last modified date and time. // Last modified date and time.
header[5] = GET_INT_LO(dostime); header[5] = (ushort)GET_INT_LO(dostime);
header[6] = GET_INT_HI(dostime); header[6] = (ushort)GET_INT_HI(dostime);
// CRC // CRC
header[7] = GET_INT_LO(crc); header[7] = (ushort)GET_INT_LO(crc);
header[8] = GET_INT_HI(crc); header[8] = (ushort)GET_INT_HI(crc);
// Compressed length: // Compressed length:
header[9] = GET_INT_LO(clen); header[9] = (ushort)GET_INT_LO(clen);
header[10] = GET_INT_HI(clen); header[10] = (ushort)GET_INT_HI(clen);
// Uncompressed length. // Uncompressed length.
header[11] = GET_INT_LO(len); header[11] = (ushort)GET_INT_LO(len);
header[12] = GET_INT_HI(len); header[12] = (ushort)GET_INT_HI(len);
// Filename length // Filename length
header[13] = SWAP_BYTES(fname_length); header[13] = (ushort)SWAP_BYTES(fname_length);
// So called "extra field" length. // So called "extra field" length.
header[14] = 0; header[14] = 0;
// Write the LOC header to the output file. // 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. // 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; static const char marker_comment[] = ZIP_ARCHIVE_MARKER_COMMENT;
...@@ -214,32 +214,32 @@ void jar::write_central_directory() { ...@@ -214,32 +214,32 @@ void jar::write_central_directory() {
ushort header[11]; ushort header[11];
// Create the End of Central Directory structure. // Create the End of Central Directory structure.
header[0] = SWAP_BYTES(0x4B50); header[0] = (ushort)SWAP_BYTES(0x4B50);
header[1] = SWAP_BYTES(0x0605); header[1] = (ushort)SWAP_BYTES(0x0605);
// disk numbers // disk numbers
header[2] = 0; header[2] = 0;
header[3] = 0; header[3] = 0;
// Number of entries in central directory. // Number of entries in central directory.
header[4] = SWAP_BYTES(central_directory_count); header[4] = (ushort)SWAP_BYTES(central_directory_count);
header[5] = SWAP_BYTES(central_directory_count); header[5] = (ushort)SWAP_BYTES(central_directory_count);
// Size of the central directory} // Size of the central directory}
header[6] = GET_INT_LO(central_directory.size()); header[6] = (ushort)GET_INT_LO((int)central_directory.size());
header[7] = GET_INT_HI(central_directory.size()); header[7] = (ushort)GET_INT_HI((int)central_directory.size());
// Offset of central directory within disk. // Offset of central directory within disk.
header[8] = GET_INT_LO(output_file_offset); header[8] = (ushort)GET_INT_LO(output_file_offset);
header[9] = GET_INT_HI(output_file_offset); header[9] = (ushort)GET_INT_HI(output_file_offset);
// zipfile comment length; // zipfile comment length;
header [10] = SWAP_BYTES(mc.len); header [10] = (ushort)SWAP_BYTES((int)mc.len);
// Write the central directory. // 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_data(central_directory.b);
// Write the End of Central Directory structure. // Write the End of Central Directory structure.
printcr(2, "end-of-directory at %d\n", output_file_offset); PRINTCR((2, "end-of-directory at %d\n", output_file_offset));
write_data(header, sizeof(header)); write_data(header, (int)sizeof(header));
printcr(2, "writing zip comment\n"); PRINTCR((2, "writing zip comment\n"));
// Write the comment. // Write the comment.
write_data(mc); write_data(mc);
} }
...@@ -249,7 +249,7 @@ void jar::write_central_directory() { ...@@ -249,7 +249,7 @@ void jar::write_central_directory() {
// Open a Jar file and initialize. // Open a Jar file and initialize.
void jar::openJarFile(const char* fname) { void jar::openJarFile(const char* fname) {
if (!jarfp) { if (!jarfp) {
printcr(1, "jar::openJarFile: opening %s\n",fname); PRINTCR((1, "jar::openJarFile: opening %s\n",fname));
jarfp = fopen(fname, "wb"); jarfp = fopen(fname, "wb");
if (!jarfp) { if (!jarfp) {
fprintf(u->errstrm, "Error: Could not open jar file: %s\n",fname); fprintf(u->errstrm, "Error: Could not open jar file: %s\n",fname);
...@@ -262,25 +262,25 @@ void jar::openJarFile(const char* fname) { ...@@ -262,25 +262,25 @@ void jar::openJarFile(const char* fname) {
void jar::addJarEntry(const char* fname, void jar::addJarEntry(const char* fname,
bool deflate_hint, int modtime, bool deflate_hint, int modtime,
bytes& head, bytes& tail) { bytes& head, bytes& tail) {
int len = head.len + tail.len; int len = (int)(head.len + tail.len);
int clen = 0; int clen = 0;
uint crc = get_crc32(0L,Z_NULL,0); uint crc = get_crc32(0,Z_NULL,0);
if (head.len != 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) 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); bool deflate = (deflate_hint && len > 0);
if (deflate) { if (deflate) {
if (deflate_bytes(head, tail) == false) { if (deflate_bytes(head, tail) == false) {
printcr(2, "Reverting to store fn=%s\t%d -> %d\n", PRINTCR((2, "Reverting to store fn=%s\t%d -> %d\n",
fname, len, deflated.size()); fname, len, deflated.size()));
deflate = false; deflate = false;
} }
} }
clen = (deflate) ? deflated.size() : len; clen = (int)((deflate) ? deflated.size() : len);
add_to_jar_directory(fname, !deflate, modtime, len, clen, crc); add_to_jar_directory(fname, !deflate, modtime, len, clen, crc);
write_jar_header( fname, !deflate, modtime, len, clen, crc); write_jar_header( fname, !deflate, modtime, len, clen, crc);
...@@ -306,7 +306,7 @@ void jar::closeJarFile(bool central) { ...@@ -306,7 +306,7 @@ void jar::closeJarFile(bool central) {
if (central) write_central_directory(); if (central) write_central_directory();
fflush(jarfp); fflush(jarfp);
fclose(jarfp); fclose(jarfp);
printcr(2, "jar::closeJarFile:closed jar-file\n"); PRINTCR((2, "jar::closeJarFile:closed jar-file\n"));
} }
reset(); reset();
} }
...@@ -338,6 +338,7 @@ uLong jar::get_dostime(int modtime) { ...@@ -338,6 +338,7 @@ uLong jar::get_dostime(int modtime) {
default_modtime = modtime; // catch a reasonable default default_modtime = modtime; // catch a reasonable default
time_t t = modtime; time_t t = modtime;
struct tm sbuf; struct tm sbuf;
(void)memset((void*)&sbuf,0, sizeof(sbuf));
struct tm* s = gmtime_r(&t, &sbuf); struct tm* s = gmtime_r(&t, &sbuf);
modtime_cache = modtime; modtime_cache = modtime;
dostime_cache = dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday, dostime_cache = dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
...@@ -355,7 +356,7 @@ uLong jar::get_dostime(int modtime) { ...@@ -355,7 +356,7 @@ uLong jar::get_dostime(int modtime) {
input data input data
*/ */
bool jar::deflate_bytes(bytes& head, bytes& tail) { bool jar::deflate_bytes(bytes& head, bytes& tail) {
int len = head.len + tail.len; int len = (int)(head.len + tail.len);
z_stream zs; z_stream zs;
BYTES_OF(zs).clear(); BYTES_OF(zs).clear();
...@@ -368,26 +369,26 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) { ...@@ -368,26 +369,26 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) {
if (error != Z_OK) { if (error != Z_OK) {
switch (error) { switch (error) {
case Z_MEM_ERROR: case Z_MEM_ERROR:
printcr(2, "Error: deflate error : Out of memory \n"); PRINTCR((2, "Error: deflate error : Out of memory \n"));
break; break;
case Z_STREAM_ERROR: case Z_STREAM_ERROR:
printcr(2,"Error: deflate error : Invalid compression level \n"); PRINTCR((2,"Error: deflate error : Invalid compression level \n"));
break; break;
case Z_VERSION_ERROR: case Z_VERSION_ERROR:
printcr(2,"Error: deflate error : Invalid version\n"); PRINTCR((2,"Error: deflate error : Invalid version\n"));
break; break;
default: default:
printcr(2,"Error: Internal deflate error error = %d\n", error); PRINTCR((2,"Error: Internal deflate error error = %d\n", error));
} }
return false; return false;
} }
deflated.empty(); deflated.empty();
zs.next_out = (uchar*) deflated.grow(len + (len/2)); 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.next_in = (uchar*)head.ptr;
zs.avail_in = head.len; zs.avail_in = (int)head.len;
bytes* first = &head; bytes* first = &head;
bytes* last = &tail; bytes* last = &tail;
...@@ -400,28 +401,28 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) { ...@@ -400,28 +401,28 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) {
if (first != null && error == Z_OK) { if (first != null && error == Z_OK) {
zs.next_in = (uchar*) first->ptr; zs.next_in = (uchar*) first->ptr;
zs.avail_in = first->len; zs.avail_in = (int)first->len;
error = deflate(&zs, Z_NO_FLUSH); error = deflate(&zs, Z_NO_FLUSH);
} }
if (error == Z_OK) { if (error == Z_OK) {
zs.next_in = (uchar*) last->ptr; zs.next_in = (uchar*) last->ptr;
zs.avail_in = last->len; zs.avail_in = (int)last->len;
error = deflate(&zs, Z_FINISH); error = deflate(&zs, Z_FINISH);
} }
if (error == Z_STREAM_END) { if (error == Z_STREAM_END) {
if (len > zs.total_out ) { if (len > (int)zs.total_out ) {
printcr(2, "deflate compressed data %d -> %d\n", len, zs.total_out); PRINTCR((2, "deflate compressed data %d -> %d\n", len, zs.total_out));
deflated.b.len = zs.total_out; deflated.b.len = zs.total_out;
deflateEnd(&zs); deflateEnd(&zs);
return true; 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); deflateEnd(&zs);
return false; return false;
} }
deflateEnd(&zs); 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; return false;
} }
...@@ -486,7 +487,7 @@ void gunzip::init(unpacker* u_) { ...@@ -486,7 +487,7 @@ void gunzip::init(unpacker* u_) {
BYTES_OF(*this).clear(); BYTES_OF(*this).clear();
u = u_; u = u_;
assert(u->gzin == null); // once only, please 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); zstream = NEW(z_stream, 1);
u->gzin = this; u->gzin = this;
u->read_input_fn = read_input_via_gzip; u->read_input_fn = read_input_via_gzip;
...@@ -555,7 +556,7 @@ void gunzip::read_fixed_field(char* buf, size_t buflen) { ...@@ -555,7 +556,7 @@ void gunzip::read_fixed_field(char* buf, size_t buflen) {
if (aborting()) return; if (aborting()) return;
jlong nr = ((unpacker::read_input_fn_t)read_input_fn) jlong nr = ((unpacker::read_input_fn_t)read_input_fn)
(u, buf, buflen, buflen); (u, buf, buflen, buflen);
if (nr != buflen) if ((size_t)nr != buflen)
u->abort("short stream header"); u->abort("short stream header");
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -69,7 +69,7 @@ struct jar { ...@@ -69,7 +69,7 @@ struct jar {
// Private Methods // Private Methods
void write_data(void* ptr, int len); 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, void add_to_jar_directory(const char* fname, bool store, int modtime,
int len, int clen, uLong crc); int len, int clen, uLong crc);
void write_jar_header(const char* fname, bool store, int modtime, void write_jar_header(const char* fname, bool store, int modtime,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册