diff options
author | Jakub Jelinek <jakub@redhat.com> | 2014-08-04 15:46:33 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2014-08-04 15:46:33 +0000 |
commit | a7084c51658d7fad0f3f33d63ef64b5f86d9ace1 (patch) | |
tree | 5286463521855c483f9a00398080e73af7eda4fc /libgfortran/runtime | |
parent | e013afce9a0ca9bd8bacf03352f325afb9b3e54e (diff) |
* runtime/memory.c (xmallocarray): Avoid division for the common case.
git-svn-id: https://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"); |