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
+2
View File
@@ -56,6 +56,8 @@ static int convert_errno_from_ucl(int r) {
// UCL extra:
case UCL_E_OVERLAP_OVERRUN:
return UPX_E_ERROR;
default:
break;
}
return UPX_E_ERROR;
}
+2
View File
@@ -64,6 +64,8 @@ static int convert_errno_from_zlib(int zr) {
return UPX_E_ERROR;
case -7: // UPX extra
return UPX_E_INPUT_OVERRUN;
default:
break;
}
return UPX_E_ERROR;
}
+9 -9
View File
@@ -85,7 +85,7 @@ inline void upx_std_call_once(upx_std_once_flag &flag, NoexceptCallable &&f) {
}
#endif // WITH_THREADS
// <type_traits> C++20 std::is_bounded_array
// <type_traits> upx_std_is_bounded_array: same as C++20 std::is_bounded_array
template <class T>
struct upx_std_is_bounded_array : public std::false_type {};
template <class T, size_t N>
@@ -93,7 +93,13 @@ struct upx_std_is_bounded_array<T[N]> : public std::true_type {};
template <class T>
inline constexpr bool upx_std_is_bounded_array_v = upx_std_is_bounded_array<T>::value;
// <type_traits> is_same_all and is_same_any: std::is_same for multiple types
// <type_traits> upx_is_integral is overloaded for BE16 & friends; see bele.h
template <class T>
struct upx_is_integral : public std::is_integral<T> {};
template <class T>
inline constexpr bool upx_is_integral_v = upx_is_integral<T>::value;
// <type_traits> util: is_same_all and is_same_any means std::is_same for multiple types
template <class T, class... Ts>
struct is_same_all : public std::conjunction<std::is_same<T, Ts>...> {};
template <class T, class... Ts>
@@ -103,12 +109,6 @@ struct is_same_any : public std::disjunction<std::is_same<T, Ts>...> {};
template <class T, class... Ts>
inline constexpr bool is_same_any_v = is_same_any<T, Ts...>::value;
// upx_is_integral is overloaded for BE16 & friends; see bele.h
template <class T>
struct upx_is_integral : public std::is_integral<T> {};
template <class T>
inline constexpr bool upx_is_integral_v = upx_is_integral<T>::value;
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
// horrible hack for broken compiler
#define upx_fake_alignas_1 __attribute__((__aligned__(1),__packed__))
@@ -461,7 +461,7 @@ constexpr bool string_le(const char *a, const char *b) {
constexpr bool string_ge(const char *a, const char *b) {
return !string_lt(a, b);
}
}
} // namespace compile_time
/*************************************************************************
// constants
+4 -4
View File
@@ -129,10 +129,10 @@ upx_off_t FileBase::seek(upx_off_t off, int whence) {
whence = SEEK_SET;
}
// SEEK_CUR falls through to here
upx_off_t rv = ::lseek(_fd, off, whence);
if (rv < 0)
upx_off_t l = ::lseek(_fd, off, whence);
if (l < 0)
throwIOException("seek error", errno);
return rv - _offset;
return l - _offset;
}
upx_off_t FileBase::tell() const {
@@ -321,7 +321,7 @@ upx_off_t OutputFile::seek(upx_off_t off, int whence) {
void OutputFile::set_extent(upx_off_t offset, upx_off_t length) {
super::set_extent(offset, length);
bytes_written = 0;
if (0 == offset && 0xffffffffLL == length) {
if (0 == offset && 0xffffffffLL == length) { // TODO: check all callers of this method
if (::fstat(_fd, &st) != 0)
throwIOException(_name, errno);
_length = st.st_size - offset;
+12 -6
View File
@@ -291,29 +291,35 @@ protected:
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>;
template <class T>
using enable_if_te16 = std::enable_if_t<is_te16_type<T>, T>;
template <class T>
using enable_if_te32 = std::enable_if_t<is_te32_type<T>, T>;
template <class T>
using enable_if_te64 = std::enable_if_t<is_te64_type<T>, T>;
template <class T, class = std::enable_if_t<is_te16_type<T>, T> >
template <class T, class = enable_if_te16<T> >
inline unsigned get_te16(const T *p) const noexcept {
return bele->get16(p);
}
template <class T, class = std::enable_if_t<is_te32_type<T>, T> >
template <class T, class = enable_if_te32<T> >
inline unsigned get_te32(const T *p) const noexcept {
return bele->get32(p);
}
template <class T, class = std::enable_if_t<is_te64_type<T>, T> >
template <class T, class = enable_if_te64<T> >
inline upx_uint64_t get_te64(const T *p) const noexcept {
return bele->get64(p);
}
template <class T, class = std::enable_if_t<is_te16_type<T>, T> >
template <class T, class = enable_if_te16<T> >
inline void set_te16(T *p, unsigned v) noexcept {
bele->set16(p, v);
}
template <class T, class = std::enable_if_t<is_te32_type<T>, T> >
template <class T, class = enable_if_te32<T> >
inline void set_te32(T *p, unsigned v) noexcept {
bele->set32(p, v);
}
template <class T, class = std::enable_if_t<is_te64_type<T>, T> >
template <class T, class = enable_if_te64<T> >
inline void set_te64(T *p, upx_uint64_t v) noexcept {
bele->set64(p, v);
}
+1 -1
View File
@@ -197,7 +197,7 @@ int PeFile::readFileHeader() {
throwCantPack(buf);
}
pe_offset += delta;
} else if (get_le32(&h) == 'P' + 'E' * 256)
} else if (get_le32((const byte *) &h) == 'P' + 'E' * 256)
break;
else
return 0;
+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();
}
+2 -2
View File
@@ -1,6 +1,6 @@
#define UPX_VERSION_HEX 0x040100 /* 04.01.00 */
#define UPX_VERSION_STRING "4.1.0"
#define UPX_VERSION_STRING4 "4.10"
#define UPX_VERSION_DATE "May 28th 2023"
#define UPX_VERSION_DATE_ISO "2023-05-28"
#define UPX_VERSION_DATE "Aug 3rd 2023"
#define UPX_VERSION_DATE_ISO "2023-08-03"
#define UPX_VERSION_YEAR "2023"
-1
View File
@@ -100,7 +100,6 @@ void do_one_file(const char *iname, char *oname) {
}
InputFile fi;
fi.st = st;
fi.sopen(iname, O_RDONLY | O_BINARY, SH_DENYWR);
#if USE_FTIME