Commit 62c986af by Jakub Jelinek Committed by Jakub Jelinek

* runtime/memory.c (xmallocarray): Avoid division for the common case.

From-SVN: r213593
parent 3696163c
2014-08-04 Jakub Jelinek <jakub@redhat.com>
* runtime/memory.c (xmallocarray): Avoid division for the common case.
2014-07-20 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2014-07-20 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/61632 PR libgfortran/61632
......
...@@ -56,7 +56,9 @@ xmallocarray (size_t nmemb, size_t size) ...@@ -56,7 +56,9 @@ xmallocarray (size_t nmemb, size_t size)
if (!nmemb || !size) if (!nmemb || !size)
size = nmemb = 1; 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; errno = ENOMEM;
os_error ("Integer overflow in xmallocarray"); os_error ("Integer overflow in xmallocarray");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment