From 9aef7b0d6f45b59fb928b0be75f9e8403502bf7c Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 4 Jan 2021 21:02:07 +0100 Subject: [PATCH] Use C++ 14 alignas(), init some struct fields just because of good practice. --- src/conf.h | 7 +----- src/filter.h | 6 ++--- src/linker.h | 62 ++++++++++++++++++++++++++-------------------------- src/packer.h | 10 ++++----- src/ui.h | 4 ++-- 5 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/conf.h b/src/conf.h index 27d5a6ca..1d019ad6 100644 --- a/src/conf.h +++ b/src/conf.h @@ -286,13 +286,8 @@ typedef size_t upx_rsize_t; #endif -#if (ACC_CC_MSC) -#define __packed_struct(s) struct s { +#define __packed_struct(s) struct alignas(1) s { #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 COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e) diff --git a/src/filter.h b/src/filter.h index 836033ac..afb069e4 100644 --- a/src/filter.h +++ b/src/filter.h @@ -67,8 +67,8 @@ public: public: // Will be set by each call to filter()/unfilter(). // Read-only afterwards. - upx_byte *buf; - unsigned buf_len; + upx_byte *buf = nullptr; + unsigned buf_len = 0; // Checksum of the buffer before applying the filter // or after un-applying the filter. @@ -76,7 +76,7 @@ public: // Input parameters used by various filters. unsigned addvalue; - const int *preferred_ctos; + const int *preferred_ctos = nullptr; // Input/output parameters used by various filters unsigned char cto; // call trick offset diff --git a/src/linker.h b/src/linker.h index c05f555a..81c3fc75 100644 --- a/src/linker.h +++ b/src/linker.h @@ -36,32 +36,32 @@ class ElfLinker : private noncopyable { friend class Packer; public: - const N_BELE_RTP::AbstractPolicy *bele; // target endianness + const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness protected: struct Section; struct Symbol; struct Relocation; - upx_byte *input; - int inputlen; - upx_byte *output; - int outputlen; + upx_byte *input = nullptr; + int inputlen = 0; + upx_byte *output = nullptr; + int outputlen = 0; - Section *head; - Section *tail; + Section *head = nullptr; + Section *tail = nullptr; - Section **sections; - Symbol **symbols; - Relocation **relocations; + Section **sections = nullptr; + Symbol **symbols = nullptr; + Relocation **relocations = nullptr; - unsigned nsections; - unsigned nsections_capacity; - unsigned nsymbols; - unsigned nsymbols_capacity; - unsigned nrelocations; - unsigned nrelocations_capacity; + unsigned nsections = 0; + unsigned nsections_capacity = 0; + unsigned nsymbols = 0; + unsigned nsymbols_capacity = 0; + unsigned nrelocations = 0; + unsigned nrelocations_capacity = 0; - bool reloc_done; + bool reloc_done = false; protected: void preprocessSections(char *start, char *end); @@ -116,32 +116,32 @@ protected: }; struct ElfLinker::Section : private noncopyable { - char *name; - void *input; - upx_byte *output; - unsigned size; - upx_uint64_t offset; - unsigned p2align; // log2 - Section *next; + char *name = nullptr; + void *input = nullptr; + upx_byte *output = nullptr; + unsigned size = 0; + upx_uint64_t offset = 0; + unsigned p2align = 0; // log2 + Section *next = nullptr; Section(const char *n, const void *i, unsigned s, unsigned a = 0); ~Section(); }; struct ElfLinker::Symbol : private noncopyable { - char *name; - Section *section; - upx_uint64_t offset; + char *name = nullptr; + Section *section = nullptr; + upx_uint64_t offset = 0; Symbol(const char *n, Section *s, upx_uint64_t o); ~Symbol(); }; struct ElfLinker::Relocation : private noncopyable { - const Section *section; - unsigned offset; - const char *type; - const Symbol *value; + const Section *section = nullptr; + unsigned offset = 0; + const char *type = nullptr; + const Symbol *value = nullptr; upx_uint64_t add; // used in .rela relocations Relocation(const Section *s, unsigned o, const char *t, const Symbol *v, upx_uint64_t a); diff --git a/src/packer.h b/src/packer.h index 6f4aeab8..ca26a89f 100644 --- a/src/packer.h +++ b/src/packer.h @@ -289,8 +289,8 @@ protected: void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); } protected: - const N_BELE_RTP::AbstractPolicy *bele; // target endianness - InputFile *fi; + const N_BELE_RTP::AbstractPolicy *bele = nullptr; // target endianness + InputFile *fi = nullptr; off_t file_size; // will get set by constructor PackHeader ph; // must be filled by canUnpack() int ph_format; @@ -301,14 +301,14 @@ protected: MemBuffer obuf; // output // UI handler - UiPacker *uip; + UiPacker *uip = nullptr; // linker - Linker *linker; + Linker *linker = nullptr; private: // private to checkPatch() - void *last_patch; + void *last_patch = nullptr; int last_patch_len; int last_patch_off; diff --git a/src/ui.h b/src/ui.h index 8b68a6c9..43068c08 100644 --- a/src/ui.h +++ b/src/ui.h @@ -87,14 +87,14 @@ public: protected: virtual void printInfo(int nl = 0); - const Packer *p; + const Packer *p = nullptr; // callback upx_callback_t cb; // internal state struct State; - State *s; + State *s = nullptr; // totals static unsigned total_files;