Mercurial > hg > CbC > CbC_gcc
diff libgfortran/runtime/memory.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
line wrap: on
line diff
--- a/libgfortran/runtime/memory.c Thu Oct 25 07:37:49 2018 +0900 +++ b/libgfortran/runtime/memory.c Thu Feb 13 11:34:05 2020 +0900 @@ -1,5 +1,5 @@ /* Memory management routines. - Copyright (C) 2002-2018 Free Software Foundation, Inc. + Copyright (C) 2002-2020 Free Software Foundation, Inc. Contributed by Paul Brook <paul@nowt.org> This file is part of the GNU Fortran runtime library (libgfortran). @@ -26,10 +26,6 @@ #include "libgfortran.h" #include <errno.h> -#ifndef SIZE_MAX -#define SIZE_MAX ((size_t)-1) -#endif - void * xmalloc (size_t n) @@ -52,18 +48,17 @@ xmallocarray (size_t nmemb, size_t size) { void *p; + size_t prod; if (!nmemb || !size) - size = nmemb = 1; -#define HALF_SIZE_T (((size_t) 1) << (__CHAR_BIT__ * sizeof (size_t) / 2)) - else if (__builtin_expect ((nmemb | size) >= HALF_SIZE_T, 0) - && nmemb > SIZE_MAX / size) + prod = 1; + else if (__builtin_mul_overflow (nmemb, size, &prod)) { errno = ENOMEM; os_error ("Integer overflow in xmallocarray"); } - p = malloc (nmemb * size); + p = malloc (prod); if (!p) os_error ("Memory allocation failed in xmallocarray");