From 7af6c4b10ee74675d0ce4bafcc02e9f9fc57394d Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 20 Sep 2016 20:59:34 +0200 Subject: [PATCH] Use new style casts. Cleanups. --- src/compress_zlib.cpp | 4 ++-- src/conf.h | 7 +++++-- src/p_lx_elf.cpp | 8 ++++---- src/packer.cpp | 1 - src/snprintf.cpp | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/compress_zlib.cpp b/src/compress_zlib.cpp index ef677337..891bd57d 100644 --- a/src/compress_zlib.cpp +++ b/src/compress_zlib.cpp @@ -99,7 +99,7 @@ int upx_zlib_compress ( const upx_bytep src, unsigned src_len, z_stream s; s.zalloc = (alloc_func) 0; s.zfree = (free_func) 0; - s.next_in = const_cast(src); // UNCONST + s.next_in = ACC_UNCONST_CAST(upx_bytep, src); s.avail_in = src_len; s.next_out = dst; s.avail_out = *dst_len; @@ -153,7 +153,7 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len, z_stream s; s.zalloc = (alloc_func) 0; s.zfree = (free_func) 0; - s.next_in = const_cast(src); // UNCONST + s.next_in = ACC_UNCONST_CAST(upx_bytep, src); s.avail_in = src_len; s.next_out = dst; s.avail_out = *dst_len; diff --git a/src/conf.h b/src/conf.h index a7e79e80..099ccda9 100644 --- a/src/conf.h +++ b/src/conf.h @@ -36,6 +36,9 @@ // ACC **************************************************************************/ +#ifndef ACC_CFG_USE_NEW_STYLE_CASTS +#define ACC_CFG_USE_NEW_STYLE_CASTS 1 +#endif #include "miniacc.h" #if !(ACC_CC_CLANG || ACC_CC_GNUC) # error "only clang and gcc are officially supported" @@ -108,8 +111,8 @@ typedef acc_uintptr_t upx_uintptr_t; #if !defined(WITH_LZMA) || (WITH_LZMA+0 == 0) # error "WITH_LZMA is missing" #endif -#if (WITH_LZMA+0 != 0x443) -# error "invalud WITH_LZMA" +#if (WITH_LZMA != 0x443) +# error "invalid WITH_LZMA version" #endif #if defined(UPX_OFFICIAL_BUILD) # if !(WITH_LZMA) || !(WITH_NRV) || !(WITH_UCL) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 0baabf3b..39e711be 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -2125,12 +2125,12 @@ PackNetBSDElf32x86::generateElfHdr( set_te32(&phdr->p_flags, Elf32_Phdr::PF_R); set_te32(&phdr->p_align, 4); - unsigned bits = get_te32( /* &np_PaX->body[4] */ - &(ACC_UNCONST_CAST(unsigned char *, (1+ np_PaX)))[4] ); + /* &np_PaX->body[4] */ + const unsigned char *p4 = &(ACC_STATIC_CAST2(const unsigned char *, const void *, (1+ np_PaX)))[4]; + unsigned bits = get_te32(p4); bits &= ~PAX_MPROTECT; bits |= PAX_NOMPROTECT; - set_te32( /* &np_PaX->body[4] */ - &(ACC_UNCONST_CAST(unsigned char *, (1+ np_PaX)))[4], bits); + set_te32(ACC_UNCONST_CAST(unsigned char *, p4), bits); sz_elf_hdrs += sz_PaX + sizeof(*phdr); note_offset += sz_PaX; diff --git a/src/packer.cpp b/src/packer.cpp index b102458d..09ba208d 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -26,7 +26,6 @@ */ -//#define WANT_STL 1 #include "conf.h" #include "file.h" #include "packer.h" diff --git a/src/snprintf.cpp b/src/snprintf.cpp index 186bda97..f52438e6 100644 --- a/src/snprintf.cpp +++ b/src/snprintf.cpp @@ -761,13 +761,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args **************************************************************************/ // UPX version with assertions -static int xdopr(char *buffer, size_t maxlen, const char *format, va_list args) { +__acc_static_noinline int xdopr(char *buffer, size_t maxlen, const char *format, va_list args) { size_t ret; // preconditions assert(maxlen < INT_MAX); if (buffer != NULL) - assert((int) maxlen > 0); + assert(maxlen > 0); else assert(maxlen == 0);