From f5392eb67249a53a303ab21ae69deb4d063e372b Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 12 Dec 2019 22:59:22 +0000 Subject: [PATCH] rtld: make checks for mmap(2) failures compliant with documentation. On error, mmap(2) returns MAP_FAILED. There is no need to use its definition or to cast. Sponsored by: The FreeBSD Foundation MFC after: 1 week --- libexec/rtld-elf/map_object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c index be95a953558a..094a0c36e07b 100644 --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -209,7 +209,7 @@ map_object(int fd, const char *path, const struct stat *sb) base_flags |= MAP_FIXED | MAP_EXCL; mapbase = mmap(base_addr, mapsize, PROT_NONE, base_flags, -1, 0); - if (mapbase == (caddr_t) -1) { + if (mapbase == MAP_FAILED) { _rtld_error("%s: mmap of entire address space failed: %s", path, rtld_strerror(errno)); goto error; @@ -266,7 +266,7 @@ map_object(int fd, const char *path, const struct stat *sb) bss_addr = mapbase + (bss_vaddr - base_vaddr); if (bss_vlimit > bss_vaddr) { /* There is something to do */ if (mmap(bss_addr, bss_vlimit - bss_vaddr, data_prot, - data_flags | MAP_ANON, -1, 0) == (caddr_t)-1) { + data_flags | MAP_ANON, -1, 0) == MAP_FAILED) { _rtld_error("%s: mmap of bss failed: %s", path, rtld_strerror(errno)); goto error1; @@ -348,7 +348,7 @@ get_elf_header(int fd, const char *path, const struct stat *sbp) hdr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_PREFAULT_READ, fd, 0); - if (hdr == (Elf_Ehdr *)MAP_FAILED) { + if (hdr == MAP_FAILED) { _rtld_error("%s: read error: %s", path, rtld_strerror(errno)); return (NULL); }