From 8e1df145129752f96e81dc657f32d2a059939c7f Mon Sep 17 00:00:00 2001 From: Avi Date: Tue, 15 Nov 2022 16:16:49 +1000 Subject: [PATCH] Fix #126, Move variables declared mid-function to the top --- elf2cfetbl.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/elf2cfetbl.c b/elf2cfetbl.c index 5e8d813..51d1408 100644 --- a/elf2cfetbl.c +++ b/elf2cfetbl.c @@ -2256,9 +2256,10 @@ int32 GetStringFromMap(char *Result, ElfStrMap *Map, int32 Key) int32 GetTblDefInfo(void) { - int32 Status = SUCCESS; - uint32 SeekOffset = 0; - int32 NumDefsRead = 0; + int32 Status = SUCCESS; + uint32 SeekOffset = 0; + int32 NumDefsRead = 0; + uint64_t calculated_offset; /* Read the data to be used to format the CFE File and Table Headers */ if ((get_st_size(SymbolPtrs[TblDefSymbolIndex]) != sizeof(CFE_TBL_FileDef_t)) && @@ -2271,8 +2272,8 @@ int32 GetTblDefInfo(void) else { /* fseek expects a long int, sh_offset and st_value are uint64 for elf64 */ - uint64_t calculated_offset = get_sh_offset(SectionHeaderPtrs[get_st_shndx(SymbolPtrs[TblDefSymbolIndex])]) + - get_st_value(SymbolPtrs[TblDefSymbolIndex]); + calculated_offset = get_sh_offset(SectionHeaderPtrs[get_st_shndx(SymbolPtrs[TblDefSymbolIndex])]) + + get_st_value(SymbolPtrs[TblDefSymbolIndex]); SeekOffset = (uint32_t)(calculated_offset); if (SeekOffset != calculated_offset) { @@ -2327,11 +2328,12 @@ int32 GetTblDefInfo(void) int32 LocateAndReadUserObject(void) { - int32 Status = SUCCESS; - int32 i = 0; - int32 j = 0; - uint32 SeekOffset = 0; - uint8 AByte; + int32 Status = SUCCESS; + int32 i = 0; + int32 j = 0; + uint32 SeekOffset = 0; + uint8 AByte; + uint64_t calculated_offset; /* Search the symbol table for the user defined object */ if (Verbose) @@ -2424,9 +2426,8 @@ int32 LocateAndReadUserObject(void) else { /* Locate data associated with symbol */ - uint64_t calculated_offset = - get_sh_offset(SectionHeaderPtrs[get_st_shndx(SymbolPtrs[UserObjSymbolIndex])]) + - get_st_value(SymbolPtrs[UserObjSymbolIndex]); + calculated_offset = get_sh_offset(SectionHeaderPtrs[get_st_shndx(SymbolPtrs[UserObjSymbolIndex])]) + + get_st_value(SymbolPtrs[UserObjSymbolIndex]); SeekOffset = (uint32_t)(calculated_offset); if (SeekOffset != calculated_offset) {