From 22178f22241b79fc0e3917e51cbc64e403fb6ff9 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 9 Oct 2016 03:12:19 +0200 Subject: [PATCH] Minor cleanups. --- src/Makefile | 2 +- src/mem.cpp | 4 ++-- src/util.h | 14 +++----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Makefile b/src/Makefile index 35b5f537..e1db6ad0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -117,7 +117,7 @@ endif mostlyclean clean distclean maintainer-clean: rm -f *.d *.map *.o *.obj *.res ./.depend upx.exe upx.out upx.ttp upx$(exeext) -./.depend compress_lzma$(objext) : override INCLUDES += -I$(UPX_LZMADIR) +./.depend compress_lzma$(objext) : INCLUDES += -I$(UPX_LZMADIR) compress_lzma$(objext) : CXXFLAGS += -Wno-shadow p_mach$(objext) : CXXFLAGS += -Wno-cast-align diff --git a/src/mem.cpp b/src/mem.cpp index 52977382..920e2994 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -76,11 +76,11 @@ bool mem_size_valid_bytes(upx_uint64_t bytes) } -int ptr_diff(const char *p1, const char *p2) +int ptr_diff(const void *p1, const void *p2) { assert(p1 != NULL); assert(p2 != NULL); - ptrdiff_t d = p1 - p2; + ptrdiff_t d = (const char *)p1 - (const char *)p2; if (p1 >= p2) assert(mem_size_valid_bytes(d)); else diff --git a/src/util.h b/src/util.h index b1f20045..e3e98d3d 100644 --- a/src/util.h +++ b/src/util.h @@ -75,21 +75,13 @@ bool mem_size_valid_bytes(upx_uint64_t bytes); #define New(type, n) new type[mem_size_get_n(sizeof(type), n)] -int ptr_diff(const char *p1, const char *p2); - -inline int ptr_diff(const unsigned char *p1, const unsigned char *p2) { - return ptr_diff((const char *) p1, (const char *) p2); -} - -inline int ptr_diff(const void *p1, const void *p2) { - return ptr_diff((const char *) p1, (const char *) p2); -} +int ptr_diff(const void *p1, const void *p2); template -inline int ptr_udiff(const T1 &p1, const T2 &p2) { +inline unsigned ptr_udiff(const T1 &p1, const T2 &p2) { int d = ptr_diff(p1, p2); assert(d >= 0); - return d; + return ACC_ICONV(unsigned, d); } /*************************************************************************