From e0ffd268772d6e2a50b885892523449b259c1b53 Mon Sep 17 00:00:00 2001 From: jdfiguer Date: Thu, 13 Jul 2023 17:23:14 -0400 Subject: [PATCH 1/3] Fix #129, Reduce cyclomatic complexity of GetElfHeader --- elf2cfetbl.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/elf2cfetbl.c b/elf2cfetbl.c index 5e8d813..ee23241 100644 --- a/elf2cfetbl.c +++ b/elf2cfetbl.c @@ -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); @@ -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; +} + /** * */ @@ -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) { From bf874a7067c1e5396ca28023e1d0cfadab6106ec Mon Sep 17 00:00:00 2001 From: jdfiguer Date: Thu, 3 Aug 2023 01:52:08 -0400 Subject: [PATCH 2/3] Fix #132, Adds CheckStatus helper functions --- elf2cfetbl.c | 78 ++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/elf2cfetbl.c b/elf2cfetbl.c index 5e8d813..6c15011 100644 --- a/elf2cfetbl.c +++ b/elf2cfetbl.c @@ -596,6 +596,24 @@ uint16_t get_st_shndx(const union Elf_Sym *Symbol) } } +/* Check status helper functions */ +void CheckStatusAndExit(int32 status) +{ + if (status != SUCCESS) + { + exit(status); + } +} + +void CheckStatusCleanupAndExit(int32 status) +{ + if (status != SUCCESS) + { + FreeMemoryAllocations(); + exit(status); + } +} + /** * */ @@ -606,30 +624,26 @@ int main(int argc, char *argv[]) int32 i = 0; Status = ProcessCmdLineOptions(argc, argv); - if (Status != SUCCESS) - return Status; + CheckStatusAndExit(Status); if (ReportVersion) OutputVersionInfo(); - Status = GetSrcFilename(); if (OutputHelp) OutputHelpInfo(); - if (Status != SUCCESS) - return Status; + + Status = GetSrcFilename(); + CheckStatusAndExit(Status); Status = OpenSrcFile(); - if (Status != SUCCESS) - return Status; + CheckStatusAndExit(Status); Status = GetElfHeader(); - if (Status != SUCCESS) - return Status; + CheckStatusAndExit(Status); /* Get the string section header first */ Status = GetSectionHeader(get_e_shstrndx(&ElfHeader), &SectionHeaderStringTable); - if (Status != SUCCESS) - return Status; + CheckStatusCleanupAndExit(Status); if (TargetWordsizeIs32Bit) { @@ -642,21 +656,13 @@ int main(int argc, char *argv[]) /* Allocate memory for all of the ELF object file section headers */ Status = AllocateSectionHeaders(); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); /* Read in each section header from input file */ for (i = 0; i < get_e_shnum(&ElfHeader); i++) { Status = GetSectionHeader(i, SectionHeaderPtrs[i]); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); } if (StringTableDataOffset == 0) @@ -667,21 +673,13 @@ int main(int argc, char *argv[]) /* Allocate memory for all of the symbol table entries */ Status = AllocateSymbols(); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); /* Read in each symbol table entry */ for (i = 0; i < NumSymbols; i++) { Status = GetSymbol(i, SymbolPtrs[i]); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); } if (TblDefSymbolIndex == -1) @@ -693,26 +691,16 @@ int main(int argc, char *argv[]) /* Read in the definition of the table file */ Status = GetTblDefInfo(); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); Status = GetDstFilename(); - if (Status != SUCCESS) - return Status; + CheckStatusAndExit(Status); Status = OpenDstFile(); - if (Status != SUCCESS) - return Status; + CheckStatusAndExit(Status); Status = LocateAndReadUserObject(); - if (Status != SUCCESS) - { - FreeMemoryAllocations(); - return Status; - } + CheckStatusCleanupAndExit(Status); Status = OutputDataToTargetFile(); From 4020dd7d5d76ac65fec798f79fe9482824a66717 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 1 Sep 2023 08:27:47 -0400 Subject: [PATCH 3/3] Bump to v3.3.0-rc4+dev36 --- CHANGELOG.md | 5 +++++ elf2cfetbl_version.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1d2c4..b1a09f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Development Build: v3.3.0-rc4+dev36 +- Adds CheckStatus helper functions +- Reduce cyclomatic complexity of GetElfHeader +- See and + ## Development Build: v3.3.0-rc4+dev30 - Remove C++-style comments - See diff --git a/elf2cfetbl_version.h b/elf2cfetbl_version.h index f9c3ed0..4528223 100644 --- a/elf2cfetbl_version.h +++ b/elf2cfetbl_version.h @@ -28,7 +28,7 @@ /* * Development Build Macro Definitions */ -#define ELF2CFETBL_BUILD_NUMBER 30 /*!< @brief Number of commits since baseline */ +#define ELF2CFETBL_BUILD_NUMBER 36 /*!< @brief Number of commits since baseline */ #define ELF2CFETBL_BUILD_BASELINE \ "v3.3.0-rc4" /*!< @brief Development Build: git tag that is the base for the current */