changeset 231:1d774010ddb9

- dynload_syms_elf.c cleanup
author Tassilo Philipp
date Sun, 16 Apr 2017 15:05:50 +0200
parents 6c7591cef6a8
children 76ed51a690a6
files dynload/dynload_syms_elf.c
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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 <dadler@uni-goettingen.de>, 
+   Copyright (c) 2007-2017 Daniel Adler <dadler@uni-goettingen.de>, 
                            Tassilo Philipp <tphilipp@potion-studios.com>,
                            Olivier Chafik <olivier.chafik@gmail.com>
 
@@ -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;