all: misc updates
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ endif
|
||||
# redirect to top-level CMake build
|
||||
#
|
||||
|
||||
# note that top-level Makefile .DEFAULT_GOAL is build/release
|
||||
# NOTE that top-level Makefile .DEFAULT_GOAL is build/release
|
||||
.DEFAULT_GOAL = build/debug
|
||||
|
||||
build/debug: $(top_srcdir)/build/debug/upx
|
||||
|
||||
@@ -541,18 +541,21 @@ void upx_compiler_sanity_check(void) noexcept {
|
||||
**************************************************************************/
|
||||
|
||||
TEST_CASE("assert_noexcept") {
|
||||
// just to make sure that our assert macros don't generate any warnings
|
||||
// just to make sure that our own assert macros don't generate any warnings
|
||||
byte dummy = 0;
|
||||
byte *ptr1 = &dummy;
|
||||
const byte *const ptr2 = &dummy;
|
||||
void *ptr3 = nullptr;
|
||||
assert(true);
|
||||
assert(1);
|
||||
assert(ptr1);
|
||||
assert(ptr2);
|
||||
assert(!ptr3);
|
||||
assert_noexcept(true);
|
||||
assert_noexcept(1);
|
||||
assert_noexcept(ptr1);
|
||||
assert_noexcept(ptr2);
|
||||
assert_noexcept(!ptr3);
|
||||
}
|
||||
|
||||
TEST_CASE("noncopyable") {
|
||||
|
||||
@@ -317,6 +317,7 @@ typedef upx_int64_t upx_off_t;
|
||||
# define attribute_format(a,b) /*empty*/
|
||||
#endif
|
||||
|
||||
// for no-op debug output
|
||||
inline void NO_printf(const char *, ...) attribute_format(1, 2);
|
||||
inline void NO_fprintf(FILE *, const char *, ...) attribute_format(2, 3);
|
||||
inline void NO_printf(const char *, ...) {}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#error "C++17 is required"
|
||||
#endif
|
||||
|
||||
// sanity check
|
||||
#if defined(__ILP32) || defined(__ILP32__)
|
||||
static_assert(sizeof(int) == 4);
|
||||
static_assert(sizeof(long) == 4);
|
||||
|
||||
+1
-1
@@ -288,7 +288,7 @@ protected:
|
||||
template <class T>
|
||||
static inline constexpr bool is_te16_type = is_same_any_v<T, byte, upx_uint16_t, BE16, LE16>;
|
||||
template <class T>
|
||||
static inline constexpr bool is_te32_type = is_same_any_v<T, byte, unsigned, BE32, LE32>;
|
||||
static inline constexpr bool is_te32_type = is_same_any_v<T, byte, upx_uint32_t, BE32, LE32>;
|
||||
template <class T>
|
||||
static inline constexpr bool is_te64_type = is_same_any_v<T, byte, upx_uint64_t, BE64, LE64>;
|
||||
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ XSPAN_NAMESPACE_BEGIN
|
||||
// debugging stats
|
||||
struct XSpanStats {
|
||||
upx_std_atomic(size_t) check_range_counter;
|
||||
// doctest checks will set these:
|
||||
// these normally will be zero, but doctest checks will populate them
|
||||
upx_std_atomic(size_t) fail_nullptr;
|
||||
upx_std_atomic(size_t) fail_nullbase;
|
||||
upx_std_atomic(size_t) fail_not_same_base;
|
||||
@@ -70,15 +70,15 @@ void xspan_fail_range_range() {
|
||||
throwCantPack("xspan_check_range: pointer out of range; take care!");
|
||||
}
|
||||
|
||||
void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) {
|
||||
if very_unlikely (p == nullptr)
|
||||
void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_bytes) {
|
||||
xspan_stats.check_range_counter += 1;
|
||||
if very_unlikely (ptr == nullptr)
|
||||
xspan_fail_range_nullptr();
|
||||
if very_unlikely (base == nullptr)
|
||||
xspan_fail_range_nullbase();
|
||||
ptrdiff_t off = (const charptr) p - (const charptr) base;
|
||||
ptrdiff_t off = (const charptr) ptr - (const charptr) base;
|
||||
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;
|
||||
NO_fprintf(stderr, "xspan_check_range done\n");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@
|
||||
#define XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION 0
|
||||
#endif
|
||||
// allow automatic conversion PtrOrSpanOrNull => PtrOrSpan => Span (with run-time checks)
|
||||
// choose between compile-time safety vs. possible run-time errors
|
||||
// choose between compile-time safety vs. possible run-time exceptions
|
||||
#ifndef XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
|
||||
#define XSPAN_CONFIG_ENABLE_SPAN_CONVERSION 1
|
||||
#endif
|
||||
|
||||
@@ -42,13 +42,13 @@
|
||||
XSPAN_NAMESPACE_BEGIN
|
||||
|
||||
// HINT: set env-var "UPX_DEBUG_DOCTEST_DISABLE=1" for improved debugging experience
|
||||
noinline void xspan_fail_nullptr();
|
||||
noinline void xspan_fail_nullbase();
|
||||
noinline void xspan_fail_not_same_base();
|
||||
noinline void xspan_fail_range_nullptr();
|
||||
noinline void xspan_fail_range_nullbase();
|
||||
noinline void xspan_fail_range_range();
|
||||
void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes);
|
||||
noinline void xspan_fail_nullptr(void);
|
||||
noinline void xspan_fail_nullbase(void);
|
||||
noinline void xspan_fail_not_same_base(void);
|
||||
noinline void xspan_fail_range_nullptr(void);
|
||||
noinline void xspan_fail_range_nullbase(void);
|
||||
noinline void xspan_fail_range_range(void);
|
||||
void xspan_check_range(const void *ptr, const void *base, ptrdiff_t size_in_bytes);
|
||||
|
||||
// help constructor to distinguish between number of elements and bytes
|
||||
struct XSpanCount {
|
||||
|
||||
@@ -113,6 +113,7 @@ forceinline ~CSelf() noexcept {}
|
||||
#endif
|
||||
noinline void invalidate() {
|
||||
assertInvariants();
|
||||
// poison the pointer
|
||||
ptr = (pointer) (upx_uintptr_t) 16; // point to non-null invalid address
|
||||
// ptr = (pointer) (void *) &ptr; // point to self
|
||||
base = ptr;
|
||||
|
||||
@@ -59,6 +59,8 @@ private:
|
||||
|
||||
public:
|
||||
#if XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION || 1
|
||||
// Ptr always provides automatic conversion to underlying type because
|
||||
// it has limited functionality
|
||||
operator pointer() const noexcept { return ptr; }
|
||||
#endif
|
||||
|
||||
@@ -75,6 +77,7 @@ public:
|
||||
#endif
|
||||
noinline void invalidate() {
|
||||
assertInvariants();
|
||||
// poison the pointer
|
||||
ptr = (pointer) (upx_uintptr_t) 16; // point to non-null invalid address
|
||||
// ptr = (pointer) (void *) &ptr; // point to self
|
||||
assertInvariants();
|
||||
|
||||
Reference in New Issue
Block a user