summaryrefslogtreecommitdiff
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
parentb4757f2e45f292c9f0e48e8dbdc003e5dbfca5ed (diff)
downloadbinutils-gdb-41977d16e4ee5b9ad01abf2cfce6edbfb6d79541.tar.gz
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.
-rw-r--r--gdb/testsuite/ChangeLog10
-rw-r--r--gdb/testsuite/gdb.base/coredump-filter.c2
-rw-r--r--gdb/testsuite/gdb.base/coremaker.c2
-rw-r--r--gdb/testsuite/gdb.base/jit-reader-host.c3
-rw-r--r--gdb/testsuite/gdb.base/sym-file-loader.c5
5 files changed, 19 insertions, 3 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 67522a76402..050a793ed05 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2020-05-20 Simon Marchi <simon.marchi@efficios.com>
+
+ 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.
+
2020-05-20 Tom Tromey <tromey@adacore.com>
* gdb.ada/array_char_idx.exp: Recognize initialized array.
diff --git a/gdb/testsuite/gdb.base/coredump-filter.c b/gdb/testsuite/gdb.base/coredump-filter.c
index f53a933a725..5786c6fe098 100644
--- a/gdb/testsuite/gdb.base/coredump-filter.c
+++ b/gdb/testsuite/gdb.base/coredump-filter.c
@@ -29,7 +29,7 @@ do_mmap (void *addr, size_t size, int prot, int flags, int fd, off_t offset)
{
void *ret = mmap (addr, size, prot, flags, fd, offset);
- assert (ret != NULL);
+ assert (ret != MAP_FAILED);
return ret;
}
diff --git a/gdb/testsuite/gdb.base/coremaker.c b/gdb/testsuite/gdb.base/coremaker.c
index 55330fd3e8a..3cc97e1e8e5 100644
--- a/gdb/testsuite/gdb.base/coremaker.c
+++ b/gdb/testsuite/gdb.base/coremaker.c
@@ -77,7 +77,7 @@ mmapdata ()
/* Now map the file into our address space as buf2 */
buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- if (buf2 == (char *) -1)
+ if (buf2 == (char *) MAP_FAILED)
{
perror ("mmap failed");
return;
diff --git a/gdb/testsuite/gdb.base/jit-reader-host.c b/gdb/testsuite/gdb.base/jit-reader-host.c
index f9c4833083a..0cf653f1fb2 100644
--- a/gdb/testsuite/gdb.base/jit-reader-host.c
+++ b/gdb/testsuite/gdb.base/jit-reader-host.c
@@ -15,6 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -59,6 +60,8 @@ main (int argc, char **argv)
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
char *code_end = code;
+ assert (code != MAP_FAILED);
+
/* "JIT" function_stack_mangle. */
memcpy (code_end, jit_function_stack_mangle_code,
sizeof (jit_function_stack_mangle_code));
diff --git a/gdb/testsuite/gdb.base/sym-file-loader.c b/gdb/testsuite/gdb.base/sym-file-loader.c
index 5fcabec4e1b..c8074b84891 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;