From 40653e40a4f5c887dad45ea60f0a13529e8c3853 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 14 May 2023 09:36:10 +0200 Subject: [PATCH] all: minor cleanups --- .github/workflows/ci.yml | 9 +++++++-- CMakeLists.txt | 24 ++++++++++++++---------- src/check/dt_check.cpp | 8 ++++++++ src/conf.h | 4 ++-- src/util/membuffer.cpp | 5 ++++- src/util/membuffer.h | 6 ++---- src/util/xspan.cpp | 4 ++-- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ce04290..96b13d47 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -384,8 +384,8 @@ jobs: - { zig_target: x86_64-macos.13-none } - { zig_target: x86_64-windows-gnu } env: - # 2023-05-12 - ZIG_DIST_VERSION: 0.11.0-dev.3097+7f7bd206d + # 2023-05-14 + ZIG_DIST_VERSION: 0.11.0-dev.3123+6f418c11e # for zig-cc wrapper scripts (see below): ZIG_CPPFLAGS: -DUPX_DOCTEST_CONFIG_MULTITHREADING ZIG_FLAGS: ${{ matrix.zig_flags }} @@ -459,5 +459,10 @@ jobs: with: name: ${{ env.artifact_name }} path: tmp/artifact + - name: 'Run install tests' + if: ${{ contains(matrix.zig_target, '-linux-') }} + run: | + (cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-cmake cmake --install .) + (cd build/zig/${ZIG_TARGET}${ZIG_PIC}/release && DESTDIR=$PWD/Install-with-make make install) # vim:set ts=2 sw=2 et: diff --git a/CMakeLists.txt b/CMakeLists.txt index 183195a7..0b559b34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,17 +190,21 @@ else() endif() # compile a target with -O2 even in Debug build -function(upx_compile_target_debug_with_O2 t) - if(MSVC_FRONTEND) - # MSVC uses some Debug compile options like -RTC1 that are incompatible with -O2 - else() - target_compile_options(${t} PRIVATE $<$:-O2>) - endif() +function(upx_compile_target_debug_with_O2) + foreach(t ${ARGV}) + if(MSVC_FRONTEND) + # MSVC uses some Debug compilation options like -RTC1 that are incompatible with -O2 + else() + target_compile_options(${t} PRIVATE $<$:-O2>) + endif() + endforeach() endfunction() -function(upx_sanitize_target t) - if(NOT UPX_CONFIG_DISABLE_SANITIZE) - if(MSVC_FRONTEND) +function(upx_sanitize_target) + foreach(t ${ARGV}) + if(UPX_CONFIG_DISABLE_SANITIZE) + # no-op + elseif(MSVC_FRONTEND) # MSVC uses -GS (similar to -fstack-protector) by default elseif(CMAKE_C_PLATFORM_ID MATCHES "^MinGW" OR MINGW OR CYGWIN) # avoid link errors with current MinGW-w64 versions @@ -211,7 +215,7 @@ function(upx_sanitize_target t) # default sanitizer for Release builds target_compile_options(${t} PRIVATE $<$:-fstack-protector>) endif() - endif() + endforeach() endfunction() set(t upx_vendor_ucl) diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index a999cbee..cea31c02 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -49,6 +49,8 @@ int upx_doctest_check(int argc, char **argv) { if (e && e[0]) { if (strcmp(e, "0") == 0) { minimal = true; + } else if (strcmp(e, "1") == 0) { + minimal = false; } else if (strcmp(e, "2") == 0) { minimal = false; duration = true; @@ -185,6 +187,12 @@ struct CheckIntegral { COMPILE_TIME_ASSERT(upx_is_integral_v) } static void check(void) { + T a = {}; + const T b = {}; + constexpr T c = {}; + assert(a == 0); + assert(b == 0); + assert(c == 0); checkU(); checkU::type>(); #if !defined(__GNUC__) diff --git a/src/conf.h b/src/conf.h index bdeb82f5..1266c12b 100644 --- a/src/conf.h +++ b/src/conf.h @@ -112,7 +112,7 @@ inline constexpr bool upx_is_integral_v = upx_is_integral::value; // horrible hack for broken compiler #define upx_fake_alignas_1 __attribute__((__aligned__(1),__packed__)) #define upx_fake_alignas_16 __attribute__((__aligned__(2))) // object file maximum 2 ??? -#define upx_fake_alignas__(a) upx_fake_alignas_ ## a +#define upx_fake_alignas__(x) upx_fake_alignas_ ## x #define alignas(x) upx_fake_alignas__(x) #endif @@ -555,7 +555,7 @@ constexpr bool string_ge(const char *a, const char *b) { #define M_IS_ZSTD(x) ((x) == M_ZSTD) -// filters +// filters internal usage #define FT_END (-1) #define FT_NONE (-2) #define FT_SKIP (-3) diff --git a/src/util/membuffer.cpp b/src/util/membuffer.cpp index 6da2a9dd..f89f4b54 100644 --- a/src/util/membuffer.cpp +++ b/src/util/membuffer.cpp @@ -25,6 +25,9 @@ */ +// A MemBuffer allocates memory on the heap, and automatically +// gets destructed when leaving scope or on exceptions. + #include "../conf.h" #include "membuffer.h" @@ -256,7 +259,7 @@ void MemBuffer::dealloc() noexcept { // **************************************************************************/ -TEST_CASE("MemBuffer") { +TEST_CASE("MemBuffer core") { MemBuffer mb; CHECK_THROWS(mb.checkState()); CHECK_THROWS(mb.alloc(0x30000000 + 1)); diff --git a/src/util/membuffer.h b/src/util/membuffer.h index d7411adf..4dfeb3a2 100644 --- a/src/util/membuffer.h +++ b/src/util/membuffer.h @@ -119,17 +119,15 @@ inline typename MemBufferBase::pointer raw_index_bytes(const MemBufferBase return mbb.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index; } -#if 1 // some more global overloads using a checked raw_bytes() call #define XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION(A, B, RType) \ typename std::enable_if::value, RType>::type -#define XSPAN_FWD_C_IS_MEMBUFFER 1 #define C MemBufferBase +#define XSPAN_FWD_C_IS_MEMBUFFER 1 #include "xspan_fwd.h" -#undef C #undef XSPAN_FWD_C_IS_MEMBUFFER +#undef C #undef XSPAN_REQUIRES_CONVERTIBLE_ANY_DIRECTION -#endif /************************************************************************* // diff --git a/src/util/xspan.cpp b/src/util/xspan.cpp index 4096b615..32995422 100644 --- a/src/util/xspan.cpp +++ b/src/util/xspan.cpp @@ -76,10 +76,10 @@ void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) if very_unlikely (base == nullptr) xspan_fail_range_nullbase(); ptrdiff_t off = (const charptr) p - (const charptr) base; - if very_unlikely (off < 0 || off > size_in_bytes) + if very_unlikely (off < 0 || off > size_in_bytes || size_in_bytes > UPX_RSIZE_MAX) xspan_fail_range_range(); xspan_stats.check_range_counter += 1; - // fprintf(stderr, "xspan_check_range done\n"); + NO_fprintf(stderr, "xspan_check_range done\n"); } XSPAN_NAMESPACE_END