all: assorted cleanups and updates
Changes include: - add a bunch of "noexcept", mostly to operators and forceinline - use "uchar" - use "charptr" - rename options_t to Options - add ptr_check_no_overlap() - rewrite p_exe.cpp, NFCI - clang-format help.cpp - spelling fixes
This commit is contained in:
@@ -78,7 +78,7 @@ int upx_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsigned
|
||||
// force users to provide *dst_len
|
||||
assert(*dst_len != 0);
|
||||
#endif
|
||||
// for UPX, we always require a reasonably sized outbut buffer
|
||||
// for UPX, we always require a reasonably sized output buffer
|
||||
assert(*dst_len >= MemBuffer::getSizeForCompression(src_len));
|
||||
|
||||
if (!cresult)
|
||||
|
||||
@@ -116,7 +116,7 @@ static bool prepare_result(lzma_compress_result_t *res, unsigned src_len, int me
|
||||
res->lit_context_bits = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// DEBUG - set sizes so that we use a maximum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MiB of stack during runtime decompression.
|
||||
res->lit_pos_bits = 4;
|
||||
@@ -524,13 +524,12 @@ const char *upx_lzma_version_string(void) { return "4.43"; }
|
||||
**************************************************************************/
|
||||
|
||||
TEST_CASE("upx_lzma_decompress") {
|
||||
typedef const upx_byte C;
|
||||
C *c_data;
|
||||
upx_byte d_buf[16];
|
||||
const byte *c_data;
|
||||
byte d_buf[16];
|
||||
unsigned d_len;
|
||||
int r;
|
||||
|
||||
c_data = (C *) "\x1a\x03\x00\x7f\xed\x3c\x00\x00\x00";
|
||||
c_data = (const byte *) "\x1a\x03\x00\x7f\xed\x3c\x00\x00\x00";
|
||||
d_len = 16;
|
||||
r = upx_lzma_decompress(c_data, 9, d_buf, &d_len, M_LZMA, nullptr);
|
||||
CHECK((r == 0 && d_len == 16));
|
||||
|
||||
@@ -113,14 +113,14 @@ int upx_ucl_compress(const upx_bytep src, unsigned src_len, upx_bytep dst, unsig
|
||||
cconf.bb_endian = 0;
|
||||
cconf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16) {
|
||||
static const unsigned char sizes[3] = {32, 8, 16};
|
||||
static const upx_uint8_t sizes[3] = {32, 8, 16};
|
||||
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
} else {
|
||||
throwInternalError("unknown compression method");
|
||||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
// optimize compression parms
|
||||
// optimize compression params
|
||||
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
|
||||
cconf.max_offset = 8 * 1024 - 1;
|
||||
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
|
||||
@@ -241,9 +241,9 @@ int upx_ucl_test_overlap(const upx_bytep buf, const upx_bytep tbuf, unsigned src
|
||||
**************************************************************************/
|
||||
|
||||
extern "C" {
|
||||
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return calloc(1, n); }
|
||||
static ucl_voidp __UCL_CDECL my_malloc(ucl_uint n) { return upx_calloc(n, 1); }
|
||||
static void __UCL_CDECL my_free(ucl_voidp p) { free(p); }
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
int upx_ucl_init(void) {
|
||||
if (ucl_init() != UCL_E_OK)
|
||||
@@ -327,13 +327,12 @@ TEST_CASE("compress_ucl") {
|
||||
#endif // DEBUG
|
||||
|
||||
TEST_CASE("upx_ucl_decompress") {
|
||||
typedef const upx_byte C;
|
||||
C *c_data;
|
||||
upx_byte d_buf[16];
|
||||
const byte *c_data;
|
||||
byte d_buf[16];
|
||||
unsigned d_len;
|
||||
int r;
|
||||
|
||||
c_data = (C *) "\x92\xff\x10\x00\x00\x00\x00\x00\x48\xff";
|
||||
c_data = (const byte *) "\x92\xff\x10\x00\x00\x00\x00\x00\x48\xff";
|
||||
d_len = 16;
|
||||
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
|
||||
CHECK((r == 0 && d_len == 16));
|
||||
@@ -343,7 +342,7 @@ TEST_CASE("upx_ucl_decompress") {
|
||||
r = upx_ucl_decompress(c_data, 10, d_buf, &d_len, M_NRV2B_8, nullptr);
|
||||
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||
|
||||
c_data = (C *) "\x92\xff\x10\x92\x49\x24\x92\xa0\xff";
|
||||
c_data = (const byte *) "\x92\xff\x10\x92\x49\x24\x92\xa0\xff";
|
||||
d_len = 16;
|
||||
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
|
||||
CHECK((r == 0 && d_len == 16));
|
||||
@@ -353,7 +352,7 @@ TEST_CASE("upx_ucl_decompress") {
|
||||
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2D_8, nullptr);
|
||||
CHECK(r == UPX_E_OUTPUT_OVERRUN);
|
||||
|
||||
c_data = (C *) "\x90\xff\xb0\x92\x49\x24\x92\xa0\xff";
|
||||
c_data = (const byte *) "\x90\xff\xb0\x92\x49\x24\x92\xa0\xff";
|
||||
d_len = 16;
|
||||
r = upx_ucl_decompress(c_data, 9, d_buf, &d_len, M_NRV2E_8, nullptr);
|
||||
CHECK((r == 0 && d_len == 16));
|
||||
|
||||
@@ -287,13 +287,12 @@ TEST_CASE("compress_zlib") {
|
||||
#endif // DEBUG
|
||||
|
||||
TEST_CASE("upx_zlib_decompress") {
|
||||
typedef const upx_byte C;
|
||||
C *c_data;
|
||||
upx_byte d_buf[16];
|
||||
const byte *c_data;
|
||||
byte d_buf[16];
|
||||
unsigned d_len;
|
||||
int r;
|
||||
|
||||
c_data = (C *) "\xfb\xff\x1f\x15\x00\x00";
|
||||
c_data = (const byte *) "\xfb\xff\x1f\x15\x00\x00";
|
||||
d_len = 16;
|
||||
r = upx_zlib_decompress(c_data, 6, d_buf, &d_len, M_DEFLATE, nullptr);
|
||||
CHECK((r == 0 && d_len == 16));
|
||||
|
||||
@@ -207,13 +207,12 @@ TEST_CASE("compress_zstd") {
|
||||
#endif // DEBUG
|
||||
|
||||
TEST_CASE("upx_zstd_decompress") {
|
||||
typedef const upx_byte C;
|
||||
C *c_data;
|
||||
upx_byte d_buf[32];
|
||||
const byte *c_data;
|
||||
byte d_buf[32];
|
||||
unsigned d_len;
|
||||
int r;
|
||||
|
||||
c_data = (C *) "\x28\xb5\x2f\xfd\x20\x20\x3d\x00\x00\x08\xff\x01\x00\x34\x4e\x08";
|
||||
c_data = (const byte *) "\x28\xb5\x2f\xfd\x20\x20\x3d\x00\x00\x08\xff\x01\x00\x34\x4e\x08";
|
||||
d_len = 32;
|
||||
r = upx_zstd_decompress(c_data, 16, d_buf, &d_len, M_ZSTD, nullptr);
|
||||
CHECK((r == 0 && d_len == 32));
|
||||
|
||||
Reference in New Issue
Block a user