PR23966, mingw failure due to 32-bit long

Message ID 20181228042243.GT30978@bubble.grove.modra.org
State New
Headers show
Series
  • PR23966, mingw failure due to 32-bit long
Related show

Commit Message

Alan Modra Dec. 28, 2018, 4:22 a.m.
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.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 7c45d52aaf..305ee22b01 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;