Use C++ 14 alignas(), init some struct fields just because of good practice.

This commit is contained in:
Markus F.X.J. Oberhumer
2021-01-04 21:02:07 +01:00
parent 2575eef3c0
commit 9aef7b0d6f
5 changed files with 42 additions and 47 deletions
+1 -6
View File
@@ -286,13 +286,8 @@ typedef size_t upx_rsize_t;
#endif #endif
#if (ACC_CC_MSC) #define __packed_struct(s) struct alignas(1) s {
#define __packed_struct(s) struct s {
#define __packed_struct_end() }; #define __packed_struct_end() };
#else
#define __packed_struct(s) __acc_struct_packed(s)
#define __packed_struct_end() __acc_struct_packed_end()
#endif
#define UNUSED(var) ACC_UNUSED(var) #define UNUSED(var) ACC_UNUSED(var)
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) #define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
+3 -3
View File
@@ -67,8 +67,8 @@ public:
public: public:
// Will be set by each call to filter()/unfilter(). // Will be set by each call to filter()/unfilter().
// Read-only afterwards. // Read-only afterwards.
upx_byte *buf; upx_byte *buf = nullptr;
unsigned buf_len; unsigned buf_len = 0;
// Checksum of the buffer before applying the filter // Checksum of the buffer before applying the filter
// or after un-applying the filter. // or after un-applying the filter.
@@ -76,7 +76,7 @@ public:
// Input parameters used by various filters. // Input parameters used by various filters.
unsigned addvalue; unsigned addvalue;
const int *preferred_ctos; const int *preferred_ctos = nullptr;
// Input/output parameters used by various filters // Input/output parameters used by various filters
unsigned char cto; // call trick offset unsigned char cto; // call trick offset
+31 -31
View File
@@ -36,32 +36,32 @@ class ElfLinker : private noncopyable {
friend class Packer; friend class Packer;
public: public:
const N_BELE_RTP::AbstractPolicy *bele; // target endianness const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness
protected: protected:
struct Section; struct Section;
struct Symbol; struct Symbol;
struct Relocation; struct Relocation;
upx_byte *input; upx_byte *input = nullptr;
int inputlen; int inputlen = 0;
upx_byte *output; upx_byte *output = nullptr;
int outputlen; int outputlen = 0;
Section *head; Section *head = nullptr;
Section *tail; Section *tail = nullptr;
Section **sections; Section **sections = nullptr;
Symbol **symbols; Symbol **symbols = nullptr;
Relocation **relocations; Relocation **relocations = nullptr;
unsigned nsections; unsigned nsections = 0;
unsigned nsections_capacity; unsigned nsections_capacity = 0;
unsigned nsymbols; unsigned nsymbols = 0;
unsigned nsymbols_capacity; unsigned nsymbols_capacity = 0;
unsigned nrelocations; unsigned nrelocations = 0;
unsigned nrelocations_capacity; unsigned nrelocations_capacity = 0;
bool reloc_done; bool reloc_done = false;
protected: protected:
void preprocessSections(char *start, char *end); void preprocessSections(char *start, char *end);
@@ -116,32 +116,32 @@ protected:
}; };
struct ElfLinker::Section : private noncopyable { struct ElfLinker::Section : private noncopyable {
char *name; char *name = nullptr;
void *input; void *input = nullptr;
upx_byte *output; upx_byte *output = nullptr;
unsigned size; unsigned size = 0;
upx_uint64_t offset; upx_uint64_t offset = 0;
unsigned p2align; // log2 unsigned p2align = 0; // log2
Section *next; Section *next = nullptr;
Section(const char *n, const void *i, unsigned s, unsigned a = 0); Section(const char *n, const void *i, unsigned s, unsigned a = 0);
~Section(); ~Section();
}; };
struct ElfLinker::Symbol : private noncopyable { struct ElfLinker::Symbol : private noncopyable {
char *name; char *name = nullptr;
Section *section; Section *section = nullptr;
upx_uint64_t offset; upx_uint64_t offset = 0;
Symbol(const char *n, Section *s, upx_uint64_t o); Symbol(const char *n, Section *s, upx_uint64_t o);
~Symbol(); ~Symbol();
}; };
struct ElfLinker::Relocation : private noncopyable { struct ElfLinker::Relocation : private noncopyable {
const Section *section; const Section *section = nullptr;
unsigned offset; unsigned offset = 0;
const char *type; const char *type = nullptr;
const Symbol *value; const Symbol *value = nullptr;
upx_uint64_t add; // used in .rela relocations upx_uint64_t add; // used in .rela relocations
Relocation(const Section *s, unsigned o, const char *t, const Symbol *v, upx_uint64_t a); Relocation(const Section *s, unsigned o, const char *t, const Symbol *v, upx_uint64_t a);
+5 -5
View File
@@ -289,8 +289,8 @@ protected:
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); } void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
protected: protected:
const N_BELE_RTP::AbstractPolicy *bele; // target endianness const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness
InputFile *fi; InputFile *fi = nullptr;
off_t file_size; // will get set by constructor off_t file_size; // will get set by constructor
PackHeader ph; // must be filled by canUnpack() PackHeader ph; // must be filled by canUnpack()
int ph_format; int ph_format;
@@ -301,14 +301,14 @@ protected:
MemBuffer obuf; // output MemBuffer obuf; // output
// UI handler // UI handler
UiPacker *uip; UiPacker *uip = nullptr;
// linker // linker
Linker *linker; Linker *linker = nullptr;
private: private:
// private to checkPatch() // private to checkPatch()
void *last_patch; void *last_patch = nullptr;
int last_patch_len; int last_patch_len;
int last_patch_off; int last_patch_off;
+2 -2
View File
@@ -87,14 +87,14 @@ public:
protected: protected:
virtual void printInfo(int nl = 0); virtual void printInfo(int nl = 0);
const Packer *p; const Packer *p = nullptr;
// callback // callback
upx_callback_t cb; upx_callback_t cb;
// internal state // internal state
struct State; struct State;
State *s; State *s = nullptr;
// totals // totals
static unsigned total_files; static unsigned total_files;