This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] PR23966, mingw failure due to 32-bit long
- From: Alan Modra <amodra at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 28 Dec 2018 04:33:35 -0000
- Subject: [binutils-gdb] PR23966, mingw failure due to 32-bit long
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cb87d9f1a49986b2eb92ac381444f4cc7c9d8a4f
commit cb87d9f1a49986b2eb92ac381444f4cc7c9d8a4f
Author: Alan Modra <amodra@gmail.com>
Date: Fri Dec 28 09:34:28 2018 +1030
PR23966, mingw failure due to 32-bit long
PR 23966
* libbfd.c (SSIZE_MAX): Define.
(bfd_malloc, bfd_realloc): Don't cast size to long to check for
"negative" values, compare against SSIZE_MAX instead.
Diff:
---
bfd/ChangeLog | 7 +++++++
bfd/libbfd.c | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 84be63b..8a073f6 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-28 Alan Modra <amodra@gmail.com>
+
+ PR 23966
+ * libbfd.c (SSIZE_MAX): Define.
+ (bfd_malloc, bfd_realloc): Don't cast size to long to check for
+ "negative" values, compare against SSIZE_MAX instead.
+
2018-12-23 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_rtype_to_howto): Remove the unused bfd
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 7c45d52..305ee22 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -254,6 +254,10 @@ _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
/* Allocate memory using malloc. */
+#ifndef SSIZE_MAX
+#define SSIZE_MAX ((size_t) -1 >> 1)
+#endif
+
void *
bfd_malloc (bfd_size_type size)
{
@@ -262,7 +266,7 @@ bfd_malloc (bfd_size_type size)
if (size != sz
/* This is to pacify memory checkers like valgrind. */
- || ((signed long) sz) < 0)
+ || sz > SSIZE_MAX)
{
bfd_set_error (bfd_error_no_memory);
return NULL;
@@ -304,7 +308,7 @@ bfd_realloc (void *ptr, bfd_size_type size)
if (size != sz
/* This is to pacify memory checkers like valgrind. */
- || ((signed long) sz) < 0)
+ || sz > SSIZE_MAX)
{
bfd_set_error (bfd_error_no_memory);
return NULL;