* runtime/memory.c (xmallocarray): Avoid division for the common case.
From-SVN: r213593
This commit is contained in:
parent
3696163cb4
commit
62c986afde
2 changed files with 7 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
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>
|
||||
|
||||
PR libgfortran/61632
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue