From 134b829d597c8308f2eb69a79a1efe8c2bc05a27 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Sat, 19 Nov 2016 16:46:01 -0800 Subject: [PATCH] prevent warning C4319: '~': zero extending 'const unsigned int' to 'upx_uint64_t' of greater size modified: linker.cpp modified: p_lx_elf.cpp modified: pefile.cpp --- src/linker.cpp | 4 +++- src/p_lx_elf.cpp | 2 +- src/pefile.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index b4316330..3cc116f8 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -435,8 +435,10 @@ int ElfLinker::addLoader(const char *sname) if (section->p2align) { assert(tail); assert(tail != section); + // .p2align must be < 32 unsigned const v = ~0u << section->p2align; - if (unsigned const l = ~v & (0u-(tail->offset + tail->size))) { + if (unsigned const l = ~v & (0u-(unsigned)(tail->offset + tail->size))) { + alignCode(l); tail->size += l; } diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index e1595cdb..6097151f 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1438,7 +1438,7 @@ bool PackLinuxElf32::canPack() exetype = 1; load_va = get_te32(&phdr->p_vaddr); unsigned file_offset = get_te32(&phdr->p_offset); - if (~page_mask & file_offset) { + if (~(upx_uint64_t)page_mask & file_offset) { if ((~page_mask & (unsigned)load_va) == file_offset) { throwCantPack("Go-language PT_LOAD: try hemfix.c, or try '--force-execve'"); // Fixing it inside upx fails because packExtent() reads original file. diff --git a/src/pefile.cpp b/src/pefile.cpp index 6347b800..422b5aee 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2414,7 +2414,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, osection[1].vsize = (osection[1].size + oam1) &~ oam1; osection[2].vsize = (osection[2].size + ncsize_virt_increase + oam1) &~ oam1; oh.imagesize = osection[2].vaddr + osection[2].vsize; - osection[0].rawdataptr = (pe_offset + sizeof(ht) + sizeof_osection + fam1) &~ fam1; + osection[0].rawdataptr = (pe_offset + sizeof(ht) + sizeof_osection + fam1) &~ (size_t)fam1; osection[1].rawdataptr = osection[0].rawdataptr; } else @@ -2422,7 +2422,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, osection[1].vsize = osection[1].size; osection[2].vsize = osection[2].size; osection[0].rawdataptr = 0; - osection[1].rawdataptr = (pe_offset + sizeof(ht) + sizeof_osection + fam1) &~ fam1; + osection[1].rawdataptr = (pe_offset + sizeof(ht) + sizeof_osection + fam1) &~ (size_t)fam1; } osection[2].rawdataptr = osection[1].rawdataptr + osection[1].size;