diff --git a/src/Makefile b/src/Makefile index d105da4a..b812168a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,10 +2,10 @@ # # usage: # `make target=linux' # linux -# `make target=djggp2' # djggp2 -# `make target=cygwin' # cygwin +# `make target=djggp2' # djggp2 2.03 +# `make target=cygwin' # cygwin 1.1.x # `make target=mingw32' # mingw32 -# `make target=no-cygwin' # mingw32 as included in cygwin +# `make target=no-cygwin' # mingw32 as included in cygwin 1.1.x # `make target=vc6' # Visual C++ 6.0 # @@ -44,7 +44,7 @@ ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),) target = sparc endif ifeq ($(target),msc) -target = vc6 +override target = vc6 endif @@ -201,6 +201,7 @@ endif # djgpp2 ifeq ($(target),cygwin) CFLAGS_M += -mno-schedule-prologue CFLAGS_M += -march=i386 -mcpu=pentium +CFLAGS_WERROR = -Werror endif ifeq ($(target),mingw32) @@ -213,6 +214,7 @@ ifeq ($(target),no-cygwin) CC = gcc -mno-cygwin CFLAGS_M += -mno-schedule-prologue CFLAGS_M += -march=i386 -mcpu=pentium +CFLAGS_WERROR = -Werror endif diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index f63d756b..95d4bf73 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -361,7 +361,7 @@ void PackLinuxI386elf::pack(OutputFile *fo) updateLoader(fo); // finally check compression ratio - if (!super::checkCompressionRatio(fo->getBytesWritten(), ph.u_len)) + if (!super::checkCompressionRatio(ph.u_len, fo->getBytesWritten())) throwNotCompressible(); } diff --git a/src/p_unix.cpp b/src/p_unix.cpp index 5f10368a..e17e88d4 100644 --- a/src/p_unix.cpp +++ b/src/p_unix.cpp @@ -197,7 +197,7 @@ void PackUnix::pack(OutputFile *fo) updateLoader(fo); // finally check compression ratio - if (!Packer::checkCompressionRatio(fo->getBytesWritten(), ph.u_len)) + if (!Packer::checkCompressionRatio(ph.u_len, fo->getBytesWritten())) throwNotCompressible(); } diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 6d0b56bc..19a6efa0 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -1915,7 +1915,7 @@ void PackW32Pe::pack(OutputFile *fo) copyOverlay(fo, overlay, &obuf); // finally check compresion ratio - if (!checkCompressionRatio(fo->getBytesWritten(), file_size)) + if (!checkCompressionRatio(file_size, fo->getBytesWritten())) throwNotCompressible(); } diff --git a/src/packer.cpp b/src/packer.cpp index 1aa24621..eee19c5c 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -222,7 +222,7 @@ bool Packer::compress(upx_bytep in, upx_bytep out, uip->endCallback(); //printf("Packer::compress: %d/%d: %7d -> %7d\n", ph.method, ph.level, ph.u_len, ph.c_len); - if (!checkCompressionRatio(ph.c_len, ph.u_len)) + if (!checkCompressionRatio(ph.u_len, ph.c_len)) return false; // return in any case if not compressible if (ph.c_len >= ph.u_len) @@ -249,8 +249,12 @@ bool Packer::compress(upx_bytep in, upx_bytep out, } -bool Packer::checkCompressionRatio(unsigned c_len, unsigned u_len) const +bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const { + assert((int)u_len > 0); + assert((int)c_len > 0); + assert((off_t)u_len < file_size); + #if 1 if (c_len >= u_len - u_len / 8) // min. 12.5% gain return false; @@ -1133,7 +1137,7 @@ void Packer::compressWithFilters(Filter *parm_ft, unsigned *parm_overlapoh, // finally check compression ratio if (best_ph.c_len + best_ph_lsize >= best_ph.u_len) throwNotCompressible(); - if (!checkCompressionRatio(best_ph.c_len, best_ph.u_len)) + if (!checkCompressionRatio(best_ph.u_len, best_ph.c_len)) throwNotCompressible(); // convenience diff --git a/src/packer.h b/src/packer.h index 0a76c98b..4911b580 100644 --- a/src/packer.h +++ b/src/packer.h @@ -148,7 +148,7 @@ protected: unsigned max_offset = 0, unsigned max_match = 0); virtual void decompress(const upx_bytep in, upx_bytep out, bool verify_checksum=true); - virtual bool checkCompressionRatio(unsigned c_len, unsigned u_len) const; + virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const; // high-level compression drivers void compressWithFilters(Filter *ft, unsigned *overlapoh,