diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-04 15:46:33 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-08-04 15:46:33 +0000 |
commit | 303b4aacb965f9163f8f07e0e6bf77d30f3aa63e (patch) | |
tree | 5286463521855c483f9a00398080e73af7eda4fc /libgfortran/runtime | |
parent | f2c1add2c05e012502b1aca5bc23d094c8c431e4 (diff) |
* runtime/memory.c (xmallocarray): Avoid division for the common case.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213593 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/memory.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index 501d870b83c..16f06065e2b 100644 --- a/libgfortran/runtime/memory.c +++ b/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"); |