aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libgfortran/runtime/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/libgfortran/runtime/memory.c')
-rw-r--r--gcc-4.9/libgfortran/runtime/memory.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc-4.9/libgfortran/runtime/memory.c b/gcc-4.9/libgfortran/runtime/memory.c
index c1e735894..d3b77de4b 100644
--- a/gcc-4.9/libgfortran/runtime/memory.c
+++ b/gcc-4.9/libgfortran/runtime/memory.c
@@ -56,7 +56,9 @@ xmallocarray (size_t nmemb, size_t size)
if (!nmemb || !size)
size = nmemb = 1;
- else if (nmemb > SIZE_MAX / size)
+#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)
{
errno = ENOMEM;
os_error ("Integer overflow in xmallocarray");