From 46527632ba0e5d10a0c37fede6b45d18b172014b Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 1 May 2022 16:02:08 +0800 Subject: [PATCH] [ELF] Do not use uninitialized members --- elf/elf.h | 20 ++++++++++---------- elf/passes.cc | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/elf/elf.h b/elf/elf.h index 0d8acd55f7..3cfc8e6064 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -1136,9 +1136,9 @@ struct Elf64Sym { } ul32 st_name; - u8 st_type : 4; - u8 st_bind : 4; - u8 st_visibility : 2; + u8 st_type : 4 = 0; + u8 st_bind : 4 = 0; + u8 st_visibility : 2 = 0; ul16 st_shndx; ul64 st_value; ul64 st_size; @@ -1162,9 +1162,9 @@ struct Elf32Sym { ul32 st_name; ul32 st_value; ul32 st_size; - u8 st_type : 4; - u8 st_bind : 4; - u8 st_visibility : 2; + u8 st_type : 4 = 0; + u8 st_bind : 4 = 0; + u8 st_visibility : 2 = 0; ul16 st_shndx; }; @@ -1195,7 +1195,7 @@ struct Elf32Shdr { }; struct Elf64Ehdr { - u8 e_ident[16]; + u8 e_ident[16] = {}; ul16 e_type; ul16 e_machine; ul32 e_version; @@ -1212,7 +1212,7 @@ struct Elf64Ehdr { }; struct Elf32Ehdr { - u8 e_ident[16]; + u8 e_ident[16] = {}; ul16 e_type; ul16 e_machine; ul32 e_version; @@ -1258,7 +1258,7 @@ struct Elf64Rel { struct Elf32Rel { ul32 r_offset; - u8 r_type; + u8 r_type = 0; ul24 r_sym; }; @@ -1271,7 +1271,7 @@ struct Elf64Rela { struct Elf32Rela { ul32 r_offset; - u8 r_type; + u8 r_type = 0; ul24 r_sym; il32 r_addend; }; diff --git a/elf/passes.cc b/elf/passes.cc index c172b7a363..8c88d6f4b0 100644 --- a/elf/passes.cc +++ b/elf/passes.cc @@ -363,7 +363,7 @@ ObjectFile *create_internal_file(Context &ctx) { obj->priority = 1; auto add = [&](std::string_view name, u8 st_type = STT_NOTYPE) { - ElfSym esym = {}; + ElfSym esym; esym.st_type = st_type; esym.st_shndx = SHN_ABS; esym.st_bind = STB_GLOBAL; @@ -429,7 +429,7 @@ ObjectFile *create_internal_file(Context &ctx) { for (i64 i = 0; i < ctx.arg.defsyms.size(); i++) { Symbol *sym = ctx.arg.defsyms[i].first; - ElfSym esym = {}; + ElfSym esym; esym.st_type = STT_NOTYPE; esym.st_shndx = SHN_ABS; esym.st_bind = STB_GLOBAL;