mirror of
https://github.com/upx/upx
synced 2025-10-05 19:20:23 +08:00
all: minor updates
This commit is contained in:
parent
41f6945be1
commit
29ce4807fb
|
@ -27,6 +27,7 @@
|
|||
// lots of tests (and probably quite a number of redundant tests)
|
||||
// modern compilers will optimize away much of this code
|
||||
|
||||
#if 0 // TODO later
|
||||
// libc++ hardenining
|
||||
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
|
||||
#if DEBUG
|
||||
|
@ -40,6 +41,7 @@
|
|||
#define _LIBCPP_ENABLE_ASSERTIONS 1
|
||||
#endif
|
||||
#endif
|
||||
#endif // TODO later
|
||||
|
||||
#include "../headers.h"
|
||||
#include <vector>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
// doctest support code implementation
|
||||
**************************************************************************/
|
||||
|
||||
#if 0 // TODO later
|
||||
// libc++ hardenining
|
||||
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
|
||||
#if DEBUG
|
||||
|
@ -41,6 +42,7 @@
|
|||
#define _LIBCPP_ENABLE_ASSERTIONS 1
|
||||
#endif
|
||||
#endif
|
||||
#endif // TODO later
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<features.h>)
|
||||
|
|
|
@ -242,7 +242,7 @@ TEST_CASE("basic xspan usage") {
|
|||
}
|
||||
|
||||
TEST_CASE("xspan array access") {
|
||||
constexpr size_t N = 16;
|
||||
const size_t N = 16;
|
||||
char buf[N];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
XSPAN_0_VAR(char, c0, buf, sizeof(buf));
|
||||
|
@ -254,6 +254,7 @@ TEST_CASE("xspan array access") {
|
|||
cp[i] += 1;
|
||||
for (size_t i = 0; i != N; ++i)
|
||||
cs[i] += 1;
|
||||
#if __cplusplus >= 201103L
|
||||
for (auto ptr = c0; ptr != c0 + N; ++ptr)
|
||||
*ptr += 1;
|
||||
for (auto ptr = c0 + 0; ptr < c0 + N; ++ptr)
|
||||
|
@ -266,6 +267,7 @@ TEST_CASE("xspan array access") {
|
|||
*ptr += 1;
|
||||
for (auto ptr = cs + 0; ptr < cs + N; ++ptr)
|
||||
*ptr += 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -685,6 +687,9 @@ TEST_CASE("Span subspan") {
|
|||
CHECK((as + 2).subspan(0, -2)[0] == 0);
|
||||
CHECK_THROWS(as.subspan(1, 0)[0]);
|
||||
CHECK_THROWS(as.subspan(1, 1)[-1]);
|
||||
CHECK(as.subspan(1)[0] == 1);
|
||||
CHECK(as.subspan(2)[0] == 2);
|
||||
CHECK(as.subspan(3)[0] == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Span constness") {
|
||||
|
|
|
@ -253,6 +253,10 @@ TEST_CASE("MemBuffer core") {
|
|||
CHECK_THROWS(mb.alloc(0x30000000 + 1));
|
||||
CHECK(raw_bytes(mb, 0) == nullptr);
|
||||
CHECK_THROWS(raw_bytes(mb, 1));
|
||||
CHECK_THROWS(mb.begin());
|
||||
CHECK_THROWS(mb.end());
|
||||
CHECK_THROWS(mb.cbegin());
|
||||
CHECK_THROWS(mb.cend());
|
||||
mb.alloc(N);
|
||||
mb.checkState();
|
||||
CHECK(mb.begin() == mb.cbegin());
|
||||
|
|
|
@ -45,8 +45,7 @@ public:
|
|||
typedef pointer iterator;
|
||||
typedef typename std::add_pointer<const T>::type const_iterator;
|
||||
protected:
|
||||
static constexpr size_t element_size = sizeof(element_type);
|
||||
static_assert(element_size >= 1 && element_size <= UPX_RSIZE_MAX_MEM);
|
||||
static const size_t element_size = sizeof(element_type);
|
||||
|
||||
protected:
|
||||
pointer ptr;
|
||||
|
|
|
@ -271,14 +271,17 @@ public:
|
|||
Self &operator=(MemBuffer &mb) { return assign(Self(mb)); }
|
||||
#endif
|
||||
|
||||
// subspan (creates a new value)
|
||||
Self subspan(ptrdiff_t offset, ptrdiff_t count) const {
|
||||
pointer begin = check_add(ptr, offset);
|
||||
pointer end = check_add(begin, count);
|
||||
if (begin <= end)
|
||||
return Self(Unchecked, begin, (end - begin) * sizeof(T), begin);
|
||||
pointer p_begin = check_add(ptr, offset);
|
||||
pointer p_end = check_add(p_begin, count);
|
||||
if (p_begin <= p_end)
|
||||
return Self(Unchecked, p_begin, (p_end - p_begin) * sizeof(T), p_begin);
|
||||
else
|
||||
return Self(Unchecked, end, (begin - end) * sizeof(T), end);
|
||||
return Self(Unchecked, p_end, (p_begin - p_end) * sizeof(T), p_end);
|
||||
}
|
||||
// subspan (creates a new value)
|
||||
Self subspan(ptrdiff_t offset) const { return subspan(offset, size() - offset); }
|
||||
|
||||
// cast to a different type (creates a new value)
|
||||
template <class U>
|
||||
|
@ -454,16 +457,16 @@ public: // raw access
|
|||
// like C++20 std::span
|
||||
pointer data() const noexcept { return ptr; }
|
||||
pointer data(size_t bytes) const { return raw_bytes(bytes); } // UPX extra
|
||||
// size_type size() const { return size_bytes() / sizeof(element_type); } // NOT USED
|
||||
size_type size() const noexcept { return size_bytes() / sizeof(element_type); }
|
||||
size_type size_bytes() const {
|
||||
assertInvariants();
|
||||
if __acc_cte (!configRequirePtr && ptr == nullptr)
|
||||
return 0;
|
||||
if __acc_cte (!configRequireBase && base == nullptr)
|
||||
return 0;
|
||||
const charptr begin = (const charptr) ptr;
|
||||
const charptr end = (const charptr) base + size_in_bytes;
|
||||
return end - begin;
|
||||
const charptr p_begin = (const charptr) ptr;
|
||||
const charptr p_end = (const charptr) base + size_in_bytes;
|
||||
return p_end - p_begin;
|
||||
}
|
||||
|
||||
#if CLANG_FORMAT_DUMMY_CLASS
|
||||
|
|
Loading…
Reference in New Issue
Block a user