# HG changeset patch # User Tassilo Philipp # Date 1492347950 -7200 # Node ID 1d774010ddb979f19fe485fdbad6728fde3ba6b8 # Parent 6c7591cef6a86a79eacb61317c9a9c2614ecf6f6 - dynload_syms_elf.c cleanup diff -r 6c7591cef6a8 -r 1d774010ddb9 dynload/dynload_syms_elf.c --- a/dynload/dynload_syms_elf.c Sun Apr 16 16:17:47 2017 +0200 +++ b/dynload/dynload_syms_elf.c Sun Apr 16 15:05:50 2017 +0200 @@ -6,7 +6,7 @@ Description: License: - Copyright (c) 2007-2015 Daniel Adler , + Copyright (c) 2007-2017 Daniel Adler , Tassilo Philipp , Olivier Chafik @@ -124,14 +124,21 @@ DLSyms* dlSymsInit(const char* libPath) { unsigned char* pMem; - void* pSectionContent; int i; struct stat st; Elf_Shdr* pS; - DLSyms* pSyms = (DLSyms*)dlAllocMem(sizeof(DLSyms)); + DLSyms* pSyms; + + if(stat(libPath, &st) == -1) + return NULL; + + i = open(libPath, O_RDONLY); + if(i == -1) + return NULL; + + pSyms = (DLSyms*)dlAllocMem(sizeof(DLSyms)); memset(pSyms, 0, sizeof(DLSyms)); - pSyms->file = open(libPath, O_RDONLY); - stat(libPath, &st); + pSyms->file = i; pSyms->fileSize = st.st_size; pSyms->pElf_Ehdr = (Elf_Ehdr*) mmap((void*) NULL, pSyms->fileSize, PROT_READ, MAP_SHARED, pSyms->file, 0); @@ -153,7 +160,7 @@ for (i = 1; i < pSyms->pElf_Ehdr->e_shnum; i++) { Elf_Shdr* pSection = &pS[i]; - pSectionContent = ((char*)pMem) + pSection->sh_offset; + void* pSectionContent = ((char*)pMem) + pSection->sh_offset; switch (pSection->sh_type) { case SHT_DYNSYM: @@ -189,9 +196,7 @@ int dlSymsCount(DLSyms* pSyms) { - if (!pSyms) - return 0; - return pSyms->nSymbols; + return pSyms ? pSyms->nSymbols : 0; } @@ -200,7 +205,7 @@ int str_index; if(!pSyms || !pSyms->pSymTab || index < 0 || index >= pSyms->nSymbols) return NULL; - + str_index = pSyms->pSymTab[index].st_name; if (str_index < 0 || str_index >= pSyms->strTabSize) return NULL;