summaryrefslogtreecommitdiffstats
path: root/libelf/elf_getphdrnum.c
diff options
context:
space:
mode:
Diffstat (limited to 'libelf/elf_getphdrnum.c')
-rw-r--r--libelf/elf_getphdrnum.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libelf/elf_getphdrnum.c b/libelf/elf_getphdrnum.c
index f91cba98..53617dfc 100644
--- a/libelf/elf_getphdrnum.c
+++ b/libelf/elf_getphdrnum.c
@@ -63,15 +63,23 @@ __elf_getphdrnum_rdlock (Elf *elf, size_t *dst)
if (elf->class == ELFCLASS32)
{
- if (likely (scns->cnt > 0
- && elf->state.elf32.scns.data[0].shdr.e32 != NULL))
- *dst = scns->data[0].shdr.e32->sh_info;
+ if (likely (scns->cnt > 0))
+ {
+ Elf_Scn *scn = &elf->state.elf32.scns.data[0];
+ Elf32_Shdr *shdr = scn->shdr.e32 ?: __elf32_getshdr_rdlock (scn);
+ if (shdr)
+ *dst = shdr->sh_info;
+ }
}
else
{
- if (likely (scns->cnt > 0
- && elf->state.elf64.scns.data[0].shdr.e64 != NULL))
- *dst = scns->data[0].shdr.e64->sh_info;
+ if (likely (scns->cnt > 0))
+ {
+ Elf_Scn *scn = &elf->state.elf64.scns.data[0];
+ Elf64_Shdr *shdr = scn->shdr.e64 ?: __elf64_getshdr_rdlock (scn);
+ if (shdr)
+ *dst = shdr->sh_info;
+ }
}
}