src: add assert_noexcept()

This commit is contained in:
Markus F.X.J. Oberhumer
2023-07-08 12:06:27 +02:00
parent 1d71dd3851
commit 682a1e97e4
12 changed files with 248 additions and 167 deletions
+12 -2
View File
@@ -233,7 +233,17 @@ void MemBuffer::alloc(upx_uint64_t bytes) {
void MemBuffer::dealloc() noexcept {
if (ptr != nullptr) {
debug_set(debug.last_return_address_dealloc, upx_return_address());
checkState();
#if DEBUG || 1
// info: calling checkState() here violates "noexcept", so we need a try block
try {
checkState();
} catch (const Throwable &e) {
printErr("unknown", e);
std::terminate();
} catch (...) {
std::terminate();
}
#endif
stats.global_dealloc_counter += 1;
stats.global_total_active_bytes -= size_in_bytes;
if (use_simple_mcheck()) {
@@ -251,7 +261,7 @@ void MemBuffer::dealloc() noexcept {
ptr = nullptr;
size_in_bytes = 0;
} else {
assert(size_in_bytes == 0);
assert_noexcept(size_in_bytes == 0);
}
}
+3 -3
View File
@@ -56,7 +56,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER(UPX_RSIZE_MAX_STR >= 1024)
upx_rsize_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra1,
upx_uint64_t extra2) {
assert(element_size > 0);
if very_unlikely (element_size > UPX_RSIZE_MAX)
if very_unlikely (element_size == 0 || element_size > UPX_RSIZE_MAX)
throwCantPack("mem_size 1; take care");
if very_unlikely (n > UPX_RSIZE_MAX)
throwCantPack("mem_size 2; take care");
@@ -72,8 +72,8 @@ upx_rsize_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t ext
bool mem_size_valid(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra1,
upx_uint64_t extra2) noexcept {
assert(element_size > 0);
if very_unlikely (element_size > UPX_RSIZE_MAX)
assert_noexcept(element_size > 0);
if very_unlikely (element_size == 0 || element_size > UPX_RSIZE_MAX)
return false;
if very_unlikely (n > UPX_RSIZE_MAX)
return false;