PECOFF: Fix a "memset clearing an object of non-trivial type" warning

This time, the warning pointed to an actual problem, because the
coff_opt_header structure contained a std::vector. I guess this happened
to work because the all-zero state was a valid representation of an
empty vector, but its not a good idea to rely on that.

I remove the memset, and have the structure clear its members in the
constructor instead.

llvm-svn: 367299
This commit is contained in:
Pavel Labath 2019-07-30 08:42:42 +00:00
parent 656ddeb2b7
commit 5c43ffd614
2 changed files with 31 additions and 33 deletions

View File

@ -267,11 +267,10 @@ ObjectFilePECOFF::ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
lldb::offset_t file_offset,
lldb::offset_t length)
: ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset),
m_dos_header(), m_coff_header(), m_coff_header_opt(), m_sect_headers(),
m_dos_header(), m_coff_header(), m_sect_headers(),
m_entry_point_address(), m_deps_filespec(), m_owningbin() {
::memset(&m_dos_header, 0, sizeof(m_dos_header));
::memset(&m_coff_header, 0, sizeof(m_coff_header));
::memset(&m_coff_header_opt, 0, sizeof(m_coff_header_opt));
}
ObjectFilePECOFF::ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
@ -279,11 +278,10 @@ ObjectFilePECOFF::ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
const lldb::ProcessSP &process_sp,
addr_t header_addr)
: ObjectFile(module_sp, process_sp, header_addr, header_data_sp),
m_dos_header(), m_coff_header(), m_coff_header_opt(), m_sect_headers(),
m_dos_header(), m_coff_header(), m_sect_headers(),
m_entry_point_address(), m_deps_filespec(), m_owningbin() {
::memset(&m_dos_header, 0, sizeof(m_dos_header));
::memset(&m_coff_header, 0, sizeof(m_coff_header));
::memset(&m_coff_header_opt, 0, sizeof(m_coff_header_opt));
}
ObjectFilePECOFF::~ObjectFilePECOFF() {}

View File

@ -171,36 +171,36 @@ protected:
} data_directory_t;
typedef struct coff_opt_header {
uint16_t magic;
uint8_t major_linker_version;
uint8_t minor_linker_version;
uint32_t code_size;
uint32_t data_size;
uint32_t bss_size;
uint32_t entry;
uint32_t code_offset;
uint32_t data_offset;
uint16_t magic = 0;
uint8_t major_linker_version = 0;
uint8_t minor_linker_version = 0;
uint32_t code_size = 0;
uint32_t data_size = 0;
uint32_t bss_size = 0;
uint32_t entry = 0;
uint32_t code_offset = 0;
uint32_t data_offset = 0;
uint64_t image_base;
uint32_t sect_alignment;
uint32_t file_alignment;
uint16_t major_os_system_version;
uint16_t minor_os_system_version;
uint16_t major_image_version;
uint16_t minor_image_version;
uint16_t major_subsystem_version;
uint16_t minor_subsystem_version;
uint32_t reserved1;
uint32_t image_size;
uint32_t header_size;
uint32_t checksum;
uint16_t subsystem;
uint16_t dll_flags;
uint64_t stack_reserve_size;
uint64_t stack_commit_size;
uint64_t heap_reserve_size;
uint64_t heap_commit_size;
uint32_t loader_flags;
uint64_t image_base = 0;
uint32_t sect_alignment = 0;
uint32_t file_alignment = 0;
uint16_t major_os_system_version = 0;
uint16_t minor_os_system_version = 0;
uint16_t major_image_version = 0;
uint16_t minor_image_version = 0;
uint16_t major_subsystem_version = 0;
uint16_t minor_subsystem_version = 0;
uint32_t reserved1 = 0;
uint32_t image_size = 0;
uint32_t header_size = 0;
uint32_t checksum = 0;
uint16_t subsystem = 0;
uint16_t dll_flags = 0;
uint64_t stack_reserve_size = 0;
uint64_t stack_commit_size = 0;
uint64_t heap_reserve_size = 0;
uint64_t heap_commit_size = 0;
uint32_t loader_flags = 0;
// uint32_t num_data_dir_entries;
std::vector<data_directory>
data_dirs; // will contain num_data_dir_entries entries