ledger-tool: Move ELF magic numbers into constant with comment (#31655)

This commit is contained in:
steviez 2023-05-15 14:32:59 -05:00 committed by GitHub
parent e5effa38b1
commit 02679eb5f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -45,6 +45,10 @@ use {
}, },
}; };
// The ELF magic number [ELFMAG0, ELFMAG1, ELFGMAG2, ELFMAG3] as defined by
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h
const ELF_MAGIC_NUMBER: [u8; 4] = [0x7f, 0x45, 0x4c, 0x46];
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Account { struct Account {
key: String, key: String,
@ -333,7 +337,7 @@ fn load_program<'a>(
let mut magic = [0u8; 4]; let mut magic = [0u8; 4];
file.read_exact(&mut magic).unwrap(); file.read_exact(&mut magic).unwrap();
file.rewind().unwrap(); file.rewind().unwrap();
let is_elf = magic == [0x7f, 0x45, 0x4c, 0x46]; let is_elf = magic == ELF_MAGIC_NUMBER;
let mut contents = Vec::new(); let mut contents = Vec::new();
file.read_to_end(&mut contents).unwrap(); file.read_to_end(&mut contents).unwrap();
let slot = Slot::default(); let slot = Slot::default();