all: enhance CMake tests; assorted updates

This commit is contained in:
Markus F.X.J. Oberhumer
2024-04-06 15:47:46 +02:00
parent ed35613d64
commit 97cf29ffbb
22 changed files with 473 additions and 398 deletions
+2 -2
View File
@@ -30,7 +30,7 @@
#if defined(__has_include)
#if __has_include(<features.h>)
#include <features.h> // for __GLIBC__
#include <features.h> // for __GLIBC__ and __GLIBC_MINOR__
#endif
#endif
@@ -42,8 +42,8 @@
#endif
#endif // _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
#if 0 // TODO later
// libc++ hardenining
#if defined(__cplusplus) && 0 // TODO later
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
#if DEBUG
#define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEBUG
+1 -1
View File
@@ -29,7 +29,7 @@
#include "system_defs.h"
#if !(__cplusplus + 0 >= 201703L)
#error "C++17 is required"
#error "FATAL ERROR: C++17 is required"
#endif
// check expected defines
+9 -3
View File
@@ -254,6 +254,12 @@ TEST_CASE("ptr_check_no_overlap 3") {
// stdlib
**************************************************************************/
const char *upx_getenv(const char *envvar) noexcept {
if (envvar != nullptr && envvar[0])
return ::getenv(envvar);
return nullptr;
}
int upx_rand(void) noexcept { return ::rand(); }
void *upx_calloc(size_t n, size_t element_size) may_throw {
@@ -430,7 +436,7 @@ struct TestSortAllPermutations {
memcpy(a, perm, sizeof(*a) * n);
sort(a, n, sizeof(*a), CompareFunc);
for (size_t i = 0; i < n; i++)
assert_noexcept((a[i] == 255 + i));
assert_noexcept(a[i] == 255 + i);
num_perms += 1;
} while (std::next_permutation(perm, perm + n));
return num_perms;
@@ -774,11 +780,11 @@ int fn_strcmp(const char *n1, const char *n2) {
// 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 {
const char *e = getenv(envvar);
const char *e = upx_getenv(envvar);
if (e != nullptr && e[0])
return strcmp(e, "0") != 0;
if (alternate_name != nullptr) {
e = getenv(alternate_name);
e = upx_getenv(alternate_name);
if (e != nullptr && e[0])
return strcmp(e, "0") != 0;
}
+2
View File
@@ -145,6 +145,8 @@ inline void ptr_invalidate_and_poison(T *(&ptr)) noexcept {
noinline void *upx_calloc(size_t n, size_t element_size) may_throw;
noinline const char *upx_getenv(const char *envvar) noexcept;
void upx_memswap(void *a, void *b, size_t bytes) noexcept;
noinline int upx_rand(void) noexcept;