all: final cleanups in preparation for release

This commit is contained in:
Markus F.X.J. Oberhumer
2023-08-03 14:20:35 +02:00
parent 13e5c13695
commit fa364d6ea3
57 changed files with 62 additions and 1087 deletions
+4 -3
View File
@@ -62,6 +62,7 @@ static noinline void init_use_simple_mcheck() noexcept {
static bool use_simple_mcheck() noexcept {
static upx_std_once_flag init_done;
upx_std_call_once(init_done, init_use_simple_mcheck);
// NOTE: clang-analyzer-unix.Malloc does not know that this flag is "constant"
return use_simple_mcheck_flag;
}
#else
@@ -195,7 +196,7 @@ void MemBuffer::checkState() const {
}
void MemBuffer::alloc(upx_uint64_t bytes) {
// NOTE: we don't automatically free a used buffer
// INFO: we don't automatically free a used buffer
assert(ptr == nullptr);
assert(size_in_bytes == 0);
//
@@ -254,9 +255,9 @@ void MemBuffer::dealloc() noexcept {
set_ne32(p + size_in_bytes, 0);
set_ne32(p + size_in_bytes + 4, 0);
//
::free(p - 16);
::free(p - 16); // NOLINT(clang-analyzer-unix.Malloc) // see NOTE above
} else {
::free(ptr);
::free(ptr); // NOLINT(clang-analyzer-unix.Malloc) // see NOTE above
}
ptr = nullptr;
size_in_bytes = 0;
+5 -1
View File
@@ -76,7 +76,11 @@ void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_byte
xspan_fail_range_nullptr();
if very_unlikely (base == nullptr)
xspan_fail_range_nullbase();
ptrdiff_t off = (const charptr) ptr - (const charptr) base;
#if defined(__SANITIZE_ADDRESS__)
const acc_intptr_t off = (acc_uintptr_t) ptr - (acc_uintptr_t) base;
#else
const ptrdiff_t off = (const charptr) ptr - (const charptr) base;
#endif
if very_unlikely (off < 0 || off > size_in_bytes || size_in_bytes > UPX_RSIZE_MAX)
xspan_fail_range_range();
NO_fprintf(stderr, "xspan_check_range done\n");
+10
View File
@@ -206,6 +206,16 @@ struct XSpanInternalDummyArg {
XSPAN_NAMESPACE_END
// poison a pointer: point to a non-null invalid address
// - resulting pointer should crash on dereference
// - this should be efficient (so no mmap() guard page etc.)
// - this should play nice with runtime checkers like ASAN, valgrind, etc.
// - this should play nice with static analyzers like clang-tidy
static forceinline void *XSPAN_GET_POISON_VOID_PTR() {
// return (void *) (upx_uintptr_t) 16; // NOLINT(performance-no-int-to-ptr)
return (void *) 16;
}
#ifndef XSPAN_DELETED_FUNCTION
#define XSPAN_DELETED_FUNCTION = delete
#endif
+1 -1
View File
@@ -114,7 +114,7 @@ forceinline ~CSelf() noexcept {}
noinline void invalidate() {
assertInvariants();
// poison the pointer: point to non-null invalid address
ptr = (pointer) (void *) (upx_uintptr_t) 16; // NOLINT(performance-no-int-to-ptr)
ptr = (pointer) XSPAN_GET_POISON_VOID_PTR();
// ptr = (pointer) (void *) &ptr; // point to self
base = ptr;
size_in_bytes = 0;
+1 -1
View File
@@ -78,7 +78,7 @@ public:
noinline void invalidate() {
assertInvariants();
// poison the pointer: point to non-null invalid address
ptr = (pointer) (void *) (upx_uintptr_t) 16; // NOLINT(performance-no-int-to-ptr)
ptr = (pointer) XSPAN_GET_POISON_VOID_PTR();
// ptr = (pointer) (void *) &ptr; // point to self
assertInvariants();
}