all: more assorted cleanups
This commit is contained in:
+9
-5
@@ -57,13 +57,17 @@ endif
|
||||
|
||||
# run the UPX testsuite
|
||||
# The expected (old) checksums are in $(top_srcdir)/.github/travis_testsuite_1-expected_sha256sums.sh
|
||||
# The actual (new) checksums are in tmp-testsuite/testsuite_1/.sha256sums.recreate
|
||||
# The actual (new) checksums are in ./tmp-testsuite/testsuite_1/.sha256sums.recreate
|
||||
ifneq ($(wildcard $(upx_testsuite_SRCDIR)/files/packed/.),)
|
||||
ifneq ($(wildcard $(top_srcdir)/.github/travis_testsuite_1.sh),)
|
||||
run-testsuite: export upx_exe := $(top_srcdir)/build/release/upx
|
||||
run-testsuite: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
||||
run-testsuite: export upx_testsuite_BUILDDIR := ./tmp-testsuite
|
||||
run-testsuite: $(top_srcdir)/build/release/upx PHONY
|
||||
run-testsuite: run-testsuite-release
|
||||
run-testsuite-%: export upx_testsuite_SRCDIR := $(upx_testsuite_SRCDIR)
|
||||
run-testsuite-%: export upx_testsuite_BUILDDIR := ./tmp-testsuite
|
||||
run-testsuite-debug: export upx_exe := $(top_srcdir)/build/debug/upx
|
||||
run-testsuite-debug: PHONY $(top_srcdir)/build/debug/upx
|
||||
time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh
|
||||
run-testsuite-release: export upx_exe := $(top_srcdir)/build/release/upx
|
||||
run-testsuite-release: PHONY $(top_srcdir)/build/release/upx
|
||||
time -p bash $(top_srcdir)/.github/travis_testsuite_1.sh
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -147,8 +147,14 @@ template <class T>
|
||||
struct TestBELE {
|
||||
__acc_static_noinline bool test(void) {
|
||||
// POD checks
|
||||
COMPILE_TIME_ASSERT(std::is_standard_layout<T>::value)
|
||||
COMPILE_TIME_ASSERT(std::is_trivial<T>::value)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(std::is_standard_layout<T>::value)
|
||||
COMPILE_TIME_ASSERT(std::is_trivial<T>::value)
|
||||
// extra checks, these are probably implied by std::is_trivial:
|
||||
COMPILE_TIME_ASSERT(std::is_nothrow_default_constructible<T>::value)
|
||||
COMPILE_TIME_ASSERT(std::is_trivially_copyable<T>::value)
|
||||
COMPILE_TIME_ASSERT(std::is_trivially_default_constructible<T>::value)
|
||||
}
|
||||
// alignment checks
|
||||
{
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(T)
|
||||
|
||||
@@ -88,14 +88,19 @@ TEST_CASE("basic xspan usage") {
|
||||
CHECK(x0 == z0p);
|
||||
CHECK(xp == z0s);
|
||||
|
||||
CHECK_NOTHROW(raw_bytes(a0, 0));
|
||||
CHECK_THROWS(raw_bytes(a0, 1));
|
||||
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
|
||||
CHECK(raw_bytes(c0, 4) == buf);
|
||||
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
|
||||
CHECK(raw_bytes(cp, 4) == buf);
|
||||
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
|
||||
CHECK(raw_bytes(cs, 4) == buf);
|
||||
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
|
||||
#if WITH_XSPAN >= 2
|
||||
CHECK_THROWS(raw_bytes(cs, 5));
|
||||
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
SUBCASE("XSPAN_x_VAR") {
|
||||
@@ -128,14 +133,19 @@ TEST_CASE("basic xspan usage") {
|
||||
CHECK(x0 == z0p);
|
||||
CHECK(xp == z0s);
|
||||
|
||||
CHECK_NOTHROW(raw_bytes(a0, 0));
|
||||
CHECK_THROWS(raw_bytes(a0, 1));
|
||||
CHECK_THROWS(raw_index_bytes(a0, 0, 0));
|
||||
CHECK(raw_bytes(c0, 4) == buf);
|
||||
CHECK(raw_index_bytes(c0, 1, 3) == buf + 1);
|
||||
CHECK(raw_bytes(cp, 4) == buf);
|
||||
CHECK(raw_index_bytes(cp, 1, 3) == buf + 1);
|
||||
CHECK(raw_bytes(cs, 4) == buf);
|
||||
CHECK(raw_index_bytes(cs, 1, 3) == buf + 1);
|
||||
#if WITH_XSPAN >= 2
|
||||
CHECK_THROWS(raw_bytes(cs, 5));
|
||||
CHECK_THROWS(raw_index_bytes(cs, 1, 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
SUBCASE("xspan in class") {
|
||||
|
||||
@@ -826,6 +826,7 @@ class MemBuffer;
|
||||
void *membuffer_get_void_ptr(MemBuffer &mb);
|
||||
unsigned membuffer_get_size(MemBuffer &mb);
|
||||
|
||||
// xspan
|
||||
#include "util/xspan.h"
|
||||
|
||||
// util/dt_check.cpp
|
||||
|
||||
+6
-6
@@ -27,8 +27,11 @@
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
static options_t global_options;
|
||||
options_t *opt = &global_options; // also see class PackMaster
|
||||
|
||||
/*************************************************************************
|
||||
// options
|
||||
// reset
|
||||
**************************************************************************/
|
||||
|
||||
void options_t::reset() {
|
||||
@@ -69,11 +72,8 @@ void options_t::reset() {
|
||||
o->win32_pe.keep_resource = "";
|
||||
}
|
||||
|
||||
static options_t global_options;
|
||||
options_t *opt = &global_options;
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// doctest checks
|
||||
**************************************************************************/
|
||||
|
||||
TEST_CASE("options_t::reset") {
|
||||
@@ -89,7 +89,7 @@ static inline void test_options(const char *(&a)[N]) {
|
||||
}
|
||||
|
||||
TEST_CASE("getopt") {
|
||||
options_t *saved_opt = opt;
|
||||
options_t *const saved_opt = opt;
|
||||
options_t local_options;
|
||||
opt = &local_options;
|
||||
opt->reset();
|
||||
|
||||
+6
-8
@@ -117,8 +117,6 @@ struct options_t final {
|
||||
CPU_286 = 2,
|
||||
CPU_386 = 3,
|
||||
CPU_486 = 4,
|
||||
CPU_586 = 5,
|
||||
CPU_686 = 6
|
||||
};
|
||||
int cpu;
|
||||
|
||||
@@ -133,12 +131,6 @@ struct options_t final {
|
||||
bool force_stub;
|
||||
bool no_reloc;
|
||||
} dos_exe;
|
||||
struct {
|
||||
bool boot_only;
|
||||
bool no_align;
|
||||
bool do_8bit;
|
||||
bool do_8mib;
|
||||
} ps1_exe;
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
bool force_execve; // force the linux/386 execve format
|
||||
@@ -151,6 +143,12 @@ struct options_t final {
|
||||
bool android_shlib; // keep some ElfXX_Shdr for dlopen()
|
||||
bool force_pie; // choose DF_1_PIE instead of is_shlib
|
||||
} o_unix;
|
||||
struct {
|
||||
bool boot_only;
|
||||
bool no_align;
|
||||
bool do_8bit;
|
||||
bool do_8mib;
|
||||
} ps1_exe;
|
||||
struct {
|
||||
bool le;
|
||||
} watcom_le;
|
||||
|
||||
+3
-3
@@ -52,15 +52,15 @@ public:
|
||||
static Packer *visitAllPackers(visit_func_t, InputFile *f, const options_t *, void *user);
|
||||
|
||||
private:
|
||||
InputFile *fi;
|
||||
Packer *p;
|
||||
InputFile *fi = nullptr;
|
||||
Packer *p = nullptr;
|
||||
|
||||
static Packer *getPacker(InputFile *f);
|
||||
static Packer *getUnpacker(InputFile *f);
|
||||
|
||||
// setup local options for each file
|
||||
options_t local_options;
|
||||
options_t *saved_opt;
|
||||
options_t *saved_opt = nullptr;
|
||||
};
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@
|
||||
#ifndef XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION
|
||||
#define XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION 0
|
||||
#endif
|
||||
// allow automatic conversion PtrOrSpanOrNull => PtrOrSpan => Span (with runtime checks)
|
||||
// allow automatic conversion PtrOrSpanOrNull => PtrOrSpan => Span (with run-time checks)
|
||||
// choose between compile-time safety vs. possible run-time errors
|
||||
#ifndef XSPAN_CONFIG_ENABLE_SPAN_CONVERSION
|
||||
#define XSPAN_CONFIG_ENABLE_SPAN_CONVERSION 1
|
||||
|
||||
@@ -200,7 +200,9 @@ template <class T>
|
||||
inline typename Ptr<T>::pointer raw_index_bytes(const Ptr<T> &a, size_t index,
|
||||
size_t size_in_bytes) {
|
||||
typedef typename Ptr<T>::element_type element_type;
|
||||
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
if very_unlikely (a.raw_ptr() == nullptr)
|
||||
throwInternalError("raw_index_bytes unexpected NULL ptr");
|
||||
return a.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -100,7 +100,9 @@ template <class T>
|
||||
inline typename PtrOrSpanOrNull<T>::pointer raw_index_bytes(const PtrOrSpanOrNull<T> &a,
|
||||
size_t index, size_t size_in_bytes) {
|
||||
typedef typename PtrOrSpanOrNull<T>::element_type element_type;
|
||||
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
if very_unlikely (a.raw_ptr() == nullptr)
|
||||
throwInternalError("raw_index_bytes unexpected NULL ptr");
|
||||
return a.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -126,7 +126,7 @@ template <class T>
|
||||
inline typename PtrOrSpan<T>::pointer raw_index_bytes(const PtrOrSpan<T> &a, size_t index,
|
||||
size_t size_in_bytes) {
|
||||
typedef typename PtrOrSpan<T>::element_type element_type;
|
||||
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
return a.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -126,7 +126,7 @@ template <class T>
|
||||
inline typename Span<T>::pointer raw_index_bytes(const Span<T> &a, size_t index,
|
||||
size_t size_in_bytes) {
|
||||
typedef typename Span<T>::element_type element_type;
|
||||
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
return a.raw_bytes(mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+18
-13
@@ -27,7 +27,7 @@
|
||||
|
||||
// work.cpp implements the central loop, and it uses class PackMaster to
|
||||
// dispatch. PackMaster by itself will instatiate a concrete subclass
|
||||
// of Packer which then does the actual work.
|
||||
// of class Packer which then does the actual work.
|
||||
|
||||
#include "conf.h"
|
||||
#include "file.h"
|
||||
@@ -171,7 +171,7 @@ void do_one_file(const char *iname, char *oname) {
|
||||
throwInternalError("invalid command");
|
||||
|
||||
// copy time stamp
|
||||
if (opt->preserve_timestamp && oname[0] && fo.isOpen()) {
|
||||
if (oname[0] && opt->preserve_timestamp && fo.isOpen()) {
|
||||
#if (USE_FTIME)
|
||||
r = setftime(fo.getFd(), &fi_ftime);
|
||||
IGNORE_ERROR(r);
|
||||
@@ -190,26 +190,24 @@ void do_one_file(const char *iname, char *oname) {
|
||||
|
||||
// rename or delete files
|
||||
if (oname[0] && !opt->output_name) {
|
||||
// FIXME: .exe or .cof etc.
|
||||
if (!opt->backup) {
|
||||
if (opt->backup) {
|
||||
char bakname[ACC_FN_PATH_MAX + 1];
|
||||
if (!makebakname(bakname, sizeof(bakname), iname))
|
||||
throwIOException("could not create a backup file name");
|
||||
FileBase::rename(iname, bakname);
|
||||
} else {
|
||||
#if (HAVE_CHMOD)
|
||||
r = chmod(iname, 0777);
|
||||
IGNORE_ERROR(r);
|
||||
#endif
|
||||
FileBase::unlink(iname);
|
||||
} else {
|
||||
// make backup
|
||||
char bakname[ACC_FN_PATH_MAX + 1];
|
||||
if (!makebakname(bakname, sizeof(bakname), iname))
|
||||
throwIOException("could not create a backup file name");
|
||||
FileBase::rename(iname, bakname);
|
||||
}
|
||||
FileBase::rename(oname, iname);
|
||||
}
|
||||
|
||||
// copy file attributes
|
||||
if (oname[0]) {
|
||||
oname[0] = 0;
|
||||
oname[0] = 0; // done with oname
|
||||
const char *name = opt->output_name ? opt->output_name : iname;
|
||||
UNUSED(name);
|
||||
#if (USE_UTIME)
|
||||
@@ -222,6 +220,13 @@ void do_one_file(const char *iname, char *oname) {
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHOWN)
|
||||
// copy the group ownership
|
||||
if (opt->preserve_ownership) {
|
||||
r = chown(name, -1, st.st_gid);
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHMOD)
|
||||
// copy permissions
|
||||
if (opt->preserve_mode) {
|
||||
@@ -230,9 +235,9 @@ void do_one_file(const char *iname, char *oname) {
|
||||
}
|
||||
#endif
|
||||
#if (HAVE_CHOWN)
|
||||
// copy the ownership
|
||||
// copy the user ownership
|
||||
if (opt->preserve_ownership) {
|
||||
r = chown(name, st.st_uid, st.st_gid);
|
||||
r = chown(name, st.st_uid, -1);
|
||||
IGNORE_ERROR(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user