all: minor cleanups
This commit is contained in:
+10
-3
@@ -504,6 +504,7 @@ void upx_compiler_sanity_check(void) noexcept {
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(upx_charptr_unit_type)
|
||||
COMPILE_TIME_ASSERT(sizeof(*((charptr) nullptr)) == 1)
|
||||
|
||||
// check UPX_VERSION_xxx
|
||||
{
|
||||
using upx::compile_time::mem_eq;
|
||||
using upx::compile_time::string_len;
|
||||
@@ -511,9 +512,15 @@ void upx_compiler_sanity_check(void) noexcept {
|
||||
static_assert(string_len(UPX_VERSION_YEAR) == 4);
|
||||
static_assert(string_len(UPX_VERSION_DATE_ISO) == 10);
|
||||
static_assert(string_len(UPX_VERSION_DATE) == 12 || string_len(UPX_VERSION_DATE) == 13);
|
||||
static_assert(mem_eq(UPX_VERSION_STRING, UPX_VERSION_STRING4, 3));
|
||||
static_assert(mem_eq(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4));
|
||||
static_assert(mem_eq(&UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE) - 5], UPX_VERSION_YEAR, 4));
|
||||
static_assert(mem_eq(UPX_VERSION_STRING4, UPX_VERSION_STRING, 3));
|
||||
static_assert(mem_eq(UPX_VERSION_YEAR, UPX_VERSION_DATE_ISO, 4));
|
||||
static_assert(mem_eq(UPX_VERSION_YEAR, &UPX_VERSION_DATE[sizeof(UPX_VERSION_DATE) - 5], 4));
|
||||
char buf[16];
|
||||
constexpr long long v = UPX_VERSION_HEX;
|
||||
upx_safe_snprintf(buf, sizeof(buf), "%lld.%lld.%lld", (v >> 16), (v >> 8) & 255, v & 255);
|
||||
assert_noexcept(strcmp(buf, UPX_VERSION_STRING) == 0);
|
||||
upx_safe_snprintf(buf, sizeof(buf), "%lld.%lld%lld", (v >> 16), (v >> 8) & 255, v & 255);
|
||||
assert_noexcept(strcmp(buf, UPX_VERSION_STRING4) == 0);
|
||||
}
|
||||
|
||||
if (gitrev[0]) {
|
||||
|
||||
+9
-11
@@ -105,19 +105,17 @@ struct PackerNames final {
|
||||
explicit PackerNames() noexcept = default;
|
||||
~PackerNames() noexcept = default;
|
||||
|
||||
static constexpr size_t MAX_NAMES = 64;
|
||||
static constexpr size_t MAX_METHODS = 8;
|
||||
static constexpr size_t MAX_FILTERS = 16;
|
||||
static constexpr unsigned MAX_NAMES = 64; // arbitrary limit, increase as needed
|
||||
struct Entry {
|
||||
const char *fname;
|
||||
const char *sname;
|
||||
size_t methods_count;
|
||||
size_t filters_count;
|
||||
unsigned methods[MAX_METHODS];
|
||||
unsigned filters[MAX_FILTERS];
|
||||
unsigned methods_count;
|
||||
unsigned filters_count;
|
||||
unsigned methods[PackerBase::MAX_METHODS];
|
||||
unsigned filters[PackerBase::MAX_FILTERS];
|
||||
};
|
||||
Entry names[MAX_NAMES];
|
||||
size_t names_count = 0;
|
||||
unsigned names_count = 0;
|
||||
const Options *o = nullptr;
|
||||
|
||||
void add(const PackerBase *pb) {
|
||||
@@ -129,14 +127,14 @@ struct PackerNames final {
|
||||
for (const int *m = pb->getCompressionMethods(M_ALL, 10); *m != M_END; m++) {
|
||||
if (*m >= 0) {
|
||||
assert_noexcept(Packer::isValidCompressionMethod(*m));
|
||||
assert_noexcept(e.methods_count < MAX_METHODS);
|
||||
assert_noexcept(e.methods_count < PackerBase::MAX_METHODS);
|
||||
e.methods[e.methods_count++] = *m;
|
||||
}
|
||||
}
|
||||
for (const int *f = pb->getFilters(); f != nullptr && *f != FT_END; f++) {
|
||||
if (*f >= 0) {
|
||||
assert_noexcept(Filter::isValidFilter(*f));
|
||||
assert_noexcept(e.filters_count < MAX_FILTERS);
|
||||
assert_noexcept(e.filters_count < PackerBase::MAX_FILTERS);
|
||||
e.filters[e.filters_count++] = *f;
|
||||
}
|
||||
}
|
||||
@@ -481,7 +479,7 @@ void show_version(bool one_line) {
|
||||
fprintf(f, "Copyright (C) 2015" "-2024 Meta Platforms, Inc. and affiliates\n");
|
||||
#endif
|
||||
#if (WITH_BZIP2)
|
||||
// see <bzlib.h>
|
||||
// see vendor/bzip2/bzlib.h
|
||||
fprintf(f, "Copyright (C) 1996" "-2010 Julian Seward\n");
|
||||
#endif
|
||||
#if !defined(DOCTEST_CONFIG_DISABLE)
|
||||
|
||||
+4
-6
@@ -1031,16 +1031,14 @@ void Packer::compressWithFilters(byte *i_ptr,
|
||||
assert(orig_ft.id == 0);
|
||||
|
||||
// prepare methods and filters
|
||||
constexpr int MAX_METHODS = 8;
|
||||
constexpr int MAX_FILTERS = 16;
|
||||
int methods[MAX_METHODS];
|
||||
int nmethods = prepareMethods(methods, ph.method, getCompressionMethods(M_ALL, ph.level));
|
||||
assert(nmethods > 0);
|
||||
assert(nmethods < MAX_METHODS);
|
||||
assert_noexcept(nmethods > 0);
|
||||
assert_noexcept(nmethods < (int) MAX_METHODS);
|
||||
int filters[MAX_FILTERS];
|
||||
int nfilters = prepareFilters(filters, filter_strategy, getFilters());
|
||||
assert(nfilters > 0);
|
||||
assert(nfilters < MAX_FILTERS);
|
||||
assert_noexcept(nfilters > 0);
|
||||
assert_noexcept(nfilters < (int) MAX_FILTERS);
|
||||
#if 0
|
||||
printf("compressWithFilters: m(%d):", nmethods);
|
||||
for (int i = 0; i < nmethods; i++)
|
||||
|
||||
@@ -76,6 +76,10 @@ public:
|
||||
virtual void doList() = 0;
|
||||
virtual void doFileInfo() = 0;
|
||||
|
||||
// arbitrary limits, increase as needed
|
||||
static constexpr unsigned MAX_METHODS = 8; // for getCompressionMethods()
|
||||
static constexpr unsigned MAX_FILTERS = 16; // for getFilters()
|
||||
|
||||
protected:
|
||||
InputFile *const fi; // reference
|
||||
union { // unnamed union
|
||||
|
||||
@@ -94,8 +94,6 @@ ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(SizeT) >= 4)
|
||||
#if (ACC_ARCH_I086)
|
||||
# define char char __huge
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
#else
|
||||
#define CLzmaDecoderState const CLzmaDecoderState
|
||||
#endif
|
||||
int LzmaDecodeProperties(CLzmaProperties *, const unsigned char *, int);
|
||||
int LzmaDecode(CLzmaDecoderState *, const unsigned char *, SizeT, SizeT *, unsigned char *, SizeT, SizeT *);
|
||||
|
||||
Reference in New Issue
Block a user