提交 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.
*
* 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));
......
/*
* 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();
}
......
/*
* 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(); }
......
/*
* 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
......
/*
* 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
......
/*
* 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"
......
/*
* 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)
......
/*
* 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
......
/*
* 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));
......
/*
* 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
......
/*
* 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
......
/*
* 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");
}
......
/*
* 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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册