aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/sym-file-loader.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-05-20 10:50:39 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-05-20 10:50:50 -0400
commit41977d16e4ee5b9ad01abf2cfce6edbfb6d79541 (patch)
tree46af3678d259d1b8b736c473707c5997c34bf0d3 /gdb/testsuite/gdb.base/sym-file-loader.c
parentb4757f2e45f292c9f0e48e8dbdc003e5dbfca5ed (diff)
downloadbinutils-41977d16e4ee5b9ad01abf2cfce6edbfb6d79541.zip
binutils-41977d16e4ee5b9ad01abf2cfce6edbfb6d79541.tar.gz
binutils-41977d16e4ee5b9ad01abf2cfce6edbfb6d79541.tar.bz2
gdb/testsuite: check mmap ret val against MAP_FAILED
Fixup a few spots in the testsuite that use mmap to consistently check the return value against MAP_FAILED. One spot in gdb.base/coredump-filter.c checked against NULL, that is wrong. The other spots either didn't check, or checked against -1. MAP_FAILED has the value -1, at least on Linux, but it's better to check against the documented define. gdb/testsuite/ChangeLog: PR gdb/26016 * gdb.base/coredump-filter.c (do_mmap): Check mmap ret val against MAP_FAILED. * gdb.base/coremaker.c (mmapdata): Likewise. * gdb.base/jit-reader-host.c (main): Likewise. * gdb.base/sym-file-loader.c (load): Likewise. (load_shlib): Likewise.
Diffstat (limited to 'gdb/testsuite/gdb.base/sym-file-loader.c')
-rw-r--r--gdb/testsuite/gdb.base/sym-file-loader.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.base/sym-file-loader.c b/gdb/testsuite/gdb.base/sym-file-loader.c
index 5fcabec..c8074b8 100644
--- a/gdb/testsuite/gdb.base/sym-file-loader.c
+++ b/gdb/testsuite/gdb.base/sym-file-loader.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
+#include <assert.h>
#include "sym-file-loader.h"
@@ -112,6 +113,8 @@ load (uint8_t *addr, Elf_External_Phdr *phdr, struct segment *tail_seg)
mapped_addr = (uint8_t *) mmap ((void *) GETADDR (phdr, p_vaddr),
GET (phdr, p_memsz), perm,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ assert (mapped_addr != MAP_FAILED);
+
mapped_size = GET (phdr, p_memsz);
from = (void *) (addr + GET (phdr, p_offset));
@@ -255,7 +258,7 @@ load_shlib (const char *file)
}
addr = (uint8_t *) mmap (NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0);
- if (addr == (uint8_t *) -1)
+ if (addr == MAP_FAILED)
{
perror ("mmap failed.");
return NULL;