Skip to content

Commit

Permalink
[ELF] Do not use uninitialized members
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed May 1, 2022
1 parent 230976a commit 4652763
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions elf/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1258,7 +1258,7 @@ struct Elf64Rel {

struct Elf32Rel {
ul32 r_offset;
u8 r_type;
u8 r_type = 0;
ul24 r_sym;
};

Expand All @@ -1271,7 +1271,7 @@ struct Elf64Rela {

struct Elf32Rela {
ul32 r_offset;
u8 r_type;
u8 r_type = 0;
ul24 r_sym;
il32 r_addend;
};
Expand Down
4 changes: 2 additions & 2 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ ObjectFile<E> *create_internal_file(Context<E> &ctx) {
obj->priority = 1;

auto add = [&](std::string_view name, u8 st_type = STT_NOTYPE) {
ElfSym<E> esym = {};
ElfSym<E> esym;
esym.st_type = st_type;
esym.st_shndx = SHN_ABS;
esym.st_bind = STB_GLOBAL;
Expand Down Expand Up @@ -429,7 +429,7 @@ ObjectFile<E> *create_internal_file(Context<E> &ctx) {

for (i64 i = 0; i < ctx.arg.defsyms.size(); i++) {
Symbol<E> *sym = ctx.arg.defsyms[i].first;
ElfSym<E> esym = {};
ElfSym<E> esym;
esym.st_type = STT_NOTYPE;
esym.st_shndx = SHN_ABS;
esym.st_bind = STB_GLOBAL;
Expand Down

0 comments on commit 4652763

Please sign in to comment.