diff options
Diffstat (limited to 'libelf/elf_getdata.c')
| -rw-r--r-- | libelf/elf_getdata.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c index 20e8e624..a21d1f9b 100644 --- a/libelf/elf_getdata.c +++ b/libelf/elf_getdata.c @@ -19,11 +19,13 @@ # include <config.h> #endif +#include <errno.h> #include <stddef.h> #include <string.h> #include <unistd.h> #include "libelfP.h" +#include <system.h> #include "common.h" #include "elf-knowledge.h" @@ -239,7 +241,7 @@ __libelf_set_rawdata (Elf_Scn *scn) if (entsize == 0) entsize = 1; - if (size % entsize != 0) + if (unlikely (size % entsize != 0)) { __libelf_seterrno (ELF_E_INVALID_DATA); return 1; @@ -250,7 +252,7 @@ __libelf_set_rawdata (Elf_Scn *scn) { /* First see whether the information in the section header is valid and it does not ask for too much. */ - if (offset + size > elf->maximum_size) + if (unlikely (offset + size > elf->maximum_size)) { /* Something is wrong. */ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); @@ -260,7 +262,7 @@ __libelf_set_rawdata (Elf_Scn *scn) scn->rawdata_base = scn->rawdata.d.d_buf = (char *) elf->map_address + elf->start_offset + offset; } - else if (elf->fildes != -1) + else if (likely (elf->fildes != -1)) { /* We have to read the data from the file. Allocate the needed memory. */ @@ -272,8 +274,9 @@ __libelf_set_rawdata (Elf_Scn *scn) return 1; } - if ((size_t) pread (elf->fildes, scn->rawdata.d.d_buf, size, - elf->start_offset + offset) != size) + ssize_t n = pread_retry (elf->fildes, scn->rawdata.d.d_buf, size, + elf->start_offset + offset); + if (unlikely ((size_t) n != size)) { /* Cannot read the data. */ free (scn->rawdata.d.d_buf); |
