CI updates and minor cleanups
This commit is contained in:
+22
-19
@@ -254,17 +254,19 @@ TEST_CASE("ptr_check_no_overlap 3") {
|
||||
// stdlib
|
||||
**************************************************************************/
|
||||
|
||||
int upx_rand(void) noexcept { return ::rand(); }
|
||||
|
||||
void *upx_calloc(size_t n, size_t element_size) may_throw {
|
||||
size_t bytes = mem_size(element_size, n); // assert size
|
||||
void *p = malloc(bytes);
|
||||
void *p = ::malloc(bytes);
|
||||
if (p != nullptr)
|
||||
memset(p, 0, bytes);
|
||||
return p;
|
||||
}
|
||||
|
||||
// simple unoptimized memswap()
|
||||
void upx_memswap(void *a, void *b, size_t n) noexcept {
|
||||
if (a != b && n != 0) {
|
||||
void upx_memswap(void *a, void *b, size_t bytes) noexcept {
|
||||
if (a != b && bytes != 0) {
|
||||
byte *x = (byte *) a;
|
||||
byte *y = (byte *) b;
|
||||
do {
|
||||
@@ -273,16 +275,16 @@ void upx_memswap(void *a, void *b, size_t n) noexcept {
|
||||
byte tmp = *x; // NOLINT(*core.uninitialized.Assign) // bogus clang-analyzer warning
|
||||
*x++ = *y;
|
||||
*y++ = tmp;
|
||||
} while (--n != 0);
|
||||
} while (--bytes != 0);
|
||||
}
|
||||
}
|
||||
|
||||
// much better memswap(), optimized for our use case in sort functions below
|
||||
static void memswap_no_overlap(byte *a, byte *b, size_t n) noexcept {
|
||||
static inline void memswap_no_overlap(byte *a, byte *b, size_t bytes) noexcept {
|
||||
#if defined(__clang__) && __clang_major__ < 15
|
||||
// work around a clang < 15 ICE (Internal Compiler Error)
|
||||
// @COMPILER_BUG @CLANG_BUG
|
||||
upx_memswap(a, b, n);
|
||||
upx_memswap(a, b, bytes);
|
||||
#else // clang bug
|
||||
upx_alignas_max byte tmp_buf[16];
|
||||
#define SWAP(x) \
|
||||
@@ -294,15 +296,15 @@ static void memswap_no_overlap(byte *a, byte *b, size_t n) noexcept {
|
||||
b += x; \
|
||||
} while (0)
|
||||
|
||||
for (; n >= 16; n -= 16)
|
||||
for (; bytes >= 16; bytes -= 16)
|
||||
SWAP(16);
|
||||
if (n & 8)
|
||||
if (bytes & 8)
|
||||
SWAP(8);
|
||||
if (n & 4)
|
||||
if (bytes & 4)
|
||||
SWAP(4);
|
||||
if (n & 2)
|
||||
if (bytes & 2)
|
||||
SWAP(2);
|
||||
if (n & 1) {
|
||||
if (bytes & 1) {
|
||||
byte tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
@@ -347,7 +349,7 @@ void upx_shellsort_memcpy(void *array, size_t n, size_t element_size, upx_compar
|
||||
upx_alignas_max byte tmp_buf[MAX_INLINE_ELEMENT_SIZE]; // buffer for one element
|
||||
byte *tmp = tmp_buf;
|
||||
if (element_size > MAX_INLINE_ELEMENT_SIZE) {
|
||||
tmp = (byte *) malloc(element_size);
|
||||
tmp = (byte *) ::malloc(element_size);
|
||||
assert(tmp != nullptr);
|
||||
}
|
||||
size_t gap = 0; // 0, 1, 4, 13, 40, 121, 364, 1093, ...
|
||||
@@ -368,7 +370,7 @@ void upx_shellsort_memcpy(void *array, size_t n, size_t element_size, upx_compar
|
||||
}
|
||||
}
|
||||
if (element_size > MAX_INLINE_ELEMENT_SIZE)
|
||||
free(tmp);
|
||||
::free(tmp);
|
||||
}
|
||||
|
||||
// wrap std::stable_sort()
|
||||
@@ -391,9 +393,10 @@ void upx_std_stable_sort(void *array, size_t n, upx_compare_func_t compare) {
|
||||
}
|
||||
|
||||
#if UPX_CONFIG_USE_STABLE_SORT
|
||||
// instantiate function templates for all element sizes we need; efficient run time, but code size
|
||||
// bloat (about 4KiB code size for each function with my current libstdc++); not really needed as
|
||||
// libc qsort() is good enough for our use cases
|
||||
// instantiate function templates for all element sizes we need; efficient
|
||||
// run-time, but code size bloat (about 4KiB code size for each function
|
||||
// with my current libstdc++); not really needed as libc qsort() is
|
||||
// good enough for our use cases
|
||||
template void upx_std_stable_sort<1>(void *, size_t, upx_compare_func_t);
|
||||
template void upx_std_stable_sort<2>(void *, size_t, upx_compare_func_t);
|
||||
template void upx_std_stable_sort<4>(void *, size_t, upx_compare_func_t);
|
||||
@@ -405,7 +408,7 @@ template void upx_std_stable_sort<56>(void *, size_t, upx_compare_func_t);
|
||||
template void upx_std_stable_sort<72>(void *, size_t, upx_compare_func_t);
|
||||
#endif
|
||||
|
||||
#if !defined(DOCTEST_CONFIG_DISABLE) && DEBUG >= 1
|
||||
#if !defined(DOCTEST_CONFIG_DISABLE) && DEBUG
|
||||
#if __cplusplus >= 202002L // use C++20 std::next_permutation() to test all permutations
|
||||
namespace {
|
||||
template <class ElementType, upx_compare_func_t CompareFunc>
|
||||
@@ -588,7 +591,7 @@ int find(const void *buf, int blen, const void *what, int wlen) noexcept {
|
||||
return -1;
|
||||
|
||||
const byte *b = (const byte *) buf;
|
||||
byte first_byte = *(const byte *) what;
|
||||
const byte first_byte = *(const byte *) what;
|
||||
|
||||
blen -= wlen;
|
||||
for (int i = 0; i <= blen; i++, b++)
|
||||
@@ -769,8 +772,8 @@ int fn_strcmp(const char *n1, const char *n2) {
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// UPX convention: any environment variable that is set and is not strictly equal to "0" is true
|
||||
bool is_envvar_true(const char *envvar, const char *alternate_name) noexcept {
|
||||
// UPX convention: any environment variable that is set and is not strictly equal to "0" is true
|
||||
const char *e = getenv(envvar);
|
||||
if (e != nullptr && e[0])
|
||||
return strcmp(e, "0") != 0;
|
||||
|
||||
Reference in New Issue
Block a user