Skip to content

Commit

Permalink
Fix #129, Reduce cyclomatic complexity of GetElfHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfiguer authored and jdfiguer committed Jul 21, 2023
1 parent 46b29f8 commit e0ffd26
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int32 GetSrcFilename(void);
int32 GetDstFilename(void);
int32 OpenSrcFile(void);
int32 OpenDstFile(void);
int32 checkELFFileMagicNumber(void);
int32 GetElfHeader(void);
void SwapElfHeader(void);
int32 GetSectionHeader(int32 SectionIndex, union Elf_Shdr *SectionHeader);
Expand Down Expand Up @@ -1460,6 +1461,18 @@ int32 OpenDstFile(void)
return SUCCESS;
}

/**
*
*/

int32 checkELFFileMagicNumber(void)
{
if (get_e_ident(&ElfHeader, EI_MAG0) != ELFMAG0 || get_e_ident(&ElfHeader, EI_MAG1) != ELFMAG1 ||
get_e_ident(&ElfHeader, EI_MAG2) != ELFMAG2 || get_e_ident(&ElfHeader, EI_MAG3) != ELFMAG3)
return FAILED;
return SUCCESS;
}

/**
*
*/
Expand Down Expand Up @@ -1493,20 +1506,15 @@ int32 GetElfHeader(void)
}

if (Verbose)
printf("ELF Header:\n");
if (Verbose)
printf(" e_ident[EI_MAG0..3] = 0x%02x,%c%c%c\n", get_e_ident(&ElfHeader, EI_MAG0),
get_e_ident(&ElfHeader, EI_MAG1), get_e_ident(&ElfHeader, EI_MAG2), get_e_ident(&ElfHeader, EI_MAG3));
{
printf("ELF Header:\n"
" e_ident[EI_MAG0..3] = 0x%02x,%c%c%c\n",
get_e_ident(&ElfHeader, EI_MAG0), get_e_ident(&ElfHeader, EI_MAG1), get_e_ident(&ElfHeader, EI_MAG2),
get_e_ident(&ElfHeader, EI_MAG3));
}

/* Verify the ELF file magic number */
if (get_e_ident(&ElfHeader, EI_MAG0) != ELFMAG0)
Status = FAILED;
if (get_e_ident(&ElfHeader, EI_MAG1) != ELFMAG1)
Status = FAILED;
if (get_e_ident(&ElfHeader, EI_MAG2) != ELFMAG2)
Status = FAILED;
if (get_e_ident(&ElfHeader, EI_MAG3) != ELFMAG3)
Status = FAILED;
Status = checkELFFileMagicNumber();

if (Status == FAILED)
{
Expand Down

0 comments on commit e0ffd26

Please sign in to comment.