From 7db3e98944c0272ab3e0c3248579e39202a7607a Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 7 Jan 2014 23:03:16 +0100 Subject: [PATCH] Small cleanups. --- src/conf.h | 4 +--- src/p_w64pep.cpp | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/conf.h b/src/conf.h index 980433dc..a7715995 100644 --- a/src/conf.h +++ b/src/conf.h @@ -336,9 +336,7 @@ typedef acc_uintptr_t upx_uintptr_t; #endif -#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800)) -#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386)) -#elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC_GNUC || ACC_CC_PATHSCALE) +#if (ACC_CC_CLANG || ACC_CC_GNUC || (ACC_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) || ACC_CC_PATHSCALE) # define __packed_struct(s) struct s { # define __packed_struct_end() } __attribute__((__packed__,__aligned__(1))); #elif (ACC_CC_WATCOMC) diff --git a/src/p_w64pep.cpp b/src/p_w64pep.cpp index 00052df9..804987ba 100644 --- a/src/p_w64pep.cpp +++ b/src/p_w64pep.cpp @@ -243,12 +243,12 @@ class ImportLinker : public ElfLinkerAMD64 unsigned len = 1 + 2 * strlen(dll) + 1 + 2 * strlen(proc) + 1 + 1; tstr dlln(name_for_dll(dll, first_char)); char *procn = new char[len]; - snprintf(procn, len - 1, "%s%c", (const char*) dlln, separator); + upx_snprintf(procn, len - 1, "%s%c", (const char*) dlln, separator); encode_name(proc, procn + strlen(procn)); return procn; } - static char zeros[sizeof(import_desc)]; + static const char zeros[sizeof(import_desc)]; enum { // the order of identifiers is very important below!! @@ -347,15 +347,18 @@ public: template void add(const C *dll, unsigned ordinal) { + ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char" assert(ordinal > 0 && ordinal < 0x10000); - char ord[20]; - snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); + char ord[1+5+1]; + upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); add((const char*) dll, ord, ordinal); } template void add(const C1 *dll, const C2 *proc) { + ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char" + ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char" assert(proc); add((const char*) dll, (const char*) proc, 0); } @@ -392,6 +395,8 @@ public: template upx_uint64_t getAddress(const C1 *dll, const C2 *proc) const { + ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char" + ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char" const Section *s = getThunk((const char*) dll, (const char*) proc, thunk_separator_first); if (s == NULL && (s = getThunk((const char*) dll,(const char*) proc, @@ -400,12 +405,13 @@ public: return s->offset; } - template - upx_uint64_t getAddress(const C1 *dll, unsigned ordinal) const + template + upx_uint64_t getAddress(const C *dll, unsigned ordinal) const { + ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char" assert(ordinal > 0 && ordinal < 0x10000); - char ord[20]; - snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); + char ord[1+5+1]; + upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); const Section *s = getThunk((const char*) dll, ord, thunk_separator_first); if (s == NULL @@ -414,14 +420,15 @@ public: return s->offset; } - template - upx_uint64_t getAddress(const C1 *dll) const + template + upx_uint64_t getAddress(const C *dll) const { + ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char" tstr sdll(name_for_dll((const char*) dll, dll_name_id)); return findSection(sdll, true)->offset; } }; -char ImportLinker::zeros[sizeof(import_desc)]; +const char ImportLinker::zeros[sizeof(import_desc)] = { 0 }; ImportLinker ilinker(8);