libdyld: fix dyld_lookup algorithm.
authorwhitequark <whitequark@whitequark.org>
Sat, 1 Aug 2015 14:21:31 +0000 (17:21 +0300)
committerwhitequark <whitequark@whitequark.org>
Sat, 1 Aug 2015 14:21:31 +0000 (17:21 +0300)
software/libdyld/dyld.c

index 3b9cfe4614f79583bcdbcec512a874a94bf73fa6..1b548f5df0917de6d91dcce9713ae7de25d64e22 100644 (file)
@@ -154,13 +154,11 @@ static unsigned long elf_hash(const unsigned char *name)
 void *dyld_lookup(const char *symbol, struct dyld_info *info) {
     unsigned hash = elf_hash((const unsigned char*) symbol);
     unsigned index = info->hash.bucket[hash % info->hash.nbucket];
-    while(strcmp(&info->strtab[info->symtab[index].st_name], symbol) &&
-          info->hash.chain[index] != STN_UNDEF)
+    while(strcmp(&info->strtab[info->symtab[index].st_name], symbol)) {
+        if(index == STN_UNDEF)
+            return NULL;
         index = info->hash.chain[index];
-
-    if(info->hash.chain[index] != STN_UNDEF) {
-        return (void*)(info->base + info->symtab[index].st_value);
-    } else {
-        return NULL;
     }
+
+    return (void*)(info->base + info->symtab[index].st_value);
 }