Compare ELFMAGIC bits as a byte slice

This commit is contained in:
Christopher Cole 2022-10-04 12:31:52 -07:00
parent aff2d776ee
commit 8373835dd8
2 changed files with 2 additions and 2 deletions

View File

@ -38,6 +38,7 @@ pub const ELFMAG1: u8 = 0x45;
pub const ELFMAG2: u8 = 0x4c;
/// ELF magic number byte 4
pub const ELFMAG3: u8 = 0x46;
pub const ELFMAGIC: [u8; 4] = [ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3];
/// ELFCLASS* define constants for e_ident[EI_CLASS]

View File

@ -75,8 +75,7 @@ impl File {
}
// Verify the magic number
if ident[0] != gabi::ELFMAG0 || ident[1] != gabi::ELFMAG1
|| ident[2] != gabi::ELFMAG2 || ident[3] != gabi::ELFMAG3 {
if ident.split_at(gabi::EI_CLASS).0 != gabi::ELFMAGIC {
return Err(ParseError::InvalidMagic);
}