summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordoko <doko@6ca36cf4-e1d1-0310-8c6f-e303bb2178ca>2014-07-31 08:08:17 +0000
committerdoko <doko@6ca36cf4-e1d1-0310-8c6f-e303bb2178ca>2014-07-31 08:08:17 +0000
commit584c7233755d00a9af9078931ac731a50784e58b (patch)
tree7c71424213544a8a5616bed97aee612cd6af348d
parent17dc74147076a971e807d14db9c666ad5346faab (diff)
downloadgcc-49-584c7233755d00a9af9078931ac731a50784e58b.tar.gz
* Update to SVN 20140731 (r213317) from the gcc-4_9-branch.
- CVE-2014-5044, fix integer overflows in array allocation in libgfortran. Closes: #756325. git-svn-id: svn://svn.debian.org/svn/gcccvs/branches/sid/gcc-4.9@7542 6ca36cf4-e1d1-0310-8c6f-e303bb2178ca
-rw-r--r--debian/changelog4
-rw-r--r--debian/patches/svn-updates.diff11047
2 files changed, 11046 insertions, 5 deletions
diff --git a/debian/changelog b/debian/changelog
index 5269b3f..b40373b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
gcc-4.9 (4.9.1-4) UNRELEASED; urgency=medium
- * Update to SVN 20140728 (r213129) from the gcc-4_9-branch.
+ * Update to SVN 20140731 (r213317) from the gcc-4_9-branch.
+ - CVE-2014-5044, fix integer overflows in array allocation in libgfortran.
+ Closes: #756325.
* Build libphobos on armel and armhf. Closes: #755390.
-- Matthias Klose <doko@debian.org> Mon, 28 Jul 2014 18:26:32 +0200
diff --git a/debian/patches/svn-updates.diff b/debian/patches/svn-updates.diff
index 22a673c..f096fdf 100644
--- a/debian/patches/svn-updates.diff
+++ b/debian/patches/svn-updates.diff
@@ -1,10 +1,10 @@
-# DP: updates from the 4.9 branch upto 20140728 (r213129).
+# DP: updates from the 4.9 branch upto 20140731 (r213317).
last_update()
{
cat > ${dir}LAST_UPDATED <EOF
-Mon Jul 28 18:19:23 CEST 2014
-Mon Jul 28 16:19:23 UTC 2014 (revision 213129)
+Thu Jul 31 09:55:11 CEST 2014
+Thu Jul 31 07:55:11 UTC 2014 (revision 213317)
EOF
}
@@ -185,6 +185,113 @@ Index: libitm/config/aarch64/target.h
+}
+
+} // namespace GTM
+Index: libstdc++-v3/include/ext/random.tcc
+===================================================================
+--- a/src/libstdc++-v3/include/ext/random.tcc (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/include/ext/random.tcc (.../branches/gcc-4_9-branch)
+@@ -1314,7 +1314,7 @@
+ operator()(_UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+- std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
++ std::__detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+ result_type __a = __param.successful_size();
+Index: libstdc++-v3/include/bits/random.tcc
+===================================================================
+--- a/src/libstdc++-v3/include/bits/random.tcc (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/include/bits/random.tcc (.../branches/gcc-4_9-branch)
+@@ -3463,6 +3463,9 @@
+ _RealType
+ generate_canonical(_UniformRandomNumberGenerator& __urng)
+ {
++ static_assert(std::is_floating_point<_RealType>::value,
++ "template argument not a floating point type");
++
+ const size_t __b
+ = std::min(static_cast<size_t>(std::numeric_limits<_RealType>::digits),
+ __bits);
+Index: libstdc++-v3/include/bits/random.h
+===================================================================
+--- a/src/libstdc++-v3/include/bits/random.h (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/include/bits/random.h (.../branches/gcc-4_9-branch)
+@@ -164,6 +164,8 @@
+ template<typename _Engine, typename _DInputType>
+ struct _Adaptor
+ {
++ static_assert(std::is_floating_point<_DInputType>::value,
++ "template argument not a floating point type");
+
+ public:
+ _Adaptor(_Engine& __g)
+Index: libstdc++-v3/ChangeLog
+===================================================================
+--- a/src/libstdc++-v3/ChangeLog (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/ChangeLog (.../branches/gcc-4_9-branch)
+@@ -1,3 +1,14 @@
++2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
++
++ PR libstdc++/60037 - SIGFPE in std::generate_canonical<unsigned int...>
++ * include/bits/random.h (_Adaptor): static_assert for non floating-point
++ result type.
++ * include/bits/random.tcc (generate_canonical): Ditto.
++ * include/ext/random.tcc (hypergeometric_distribution::operator()):
++ Use double as a rng result type.
++ * testsuite/26_numerics/random/pr60037-neg.cc: New.
++ * testsuite/ext/random/hypergeometric_distribution/pr60037.cc: New.
++
+ 2014-07-16 Release Manager
+
+ * GCC 4.9.1 released.
+Index: libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
+===================================================================
+--- a/src/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc (.../branches/gcc-4_9-branch)
+@@ -0,0 +1,15 @@
++// { dg-do compile }
++// { dg-options "-std=gnu++11" }
++
++#include <random>
++
++std::mt19937 urng;
++
++std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng);
++
++auto x = std::generate_canonical<std::size_t,
++ std::numeric_limits<std::size_t>::digits>(urng);
++
++// { dg-error "static assertion failed: template argument not a floating point type" "" { target *-*-* } 167 }
++
++// { dg-error "static assertion failed: template argument not a floating point type" "" { target *-*-* } 3466 }
+Index: libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc
+===================================================================
+--- a/src/libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc (.../tags/gcc_4_9_1_release)
++++ b/src/libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc (.../branches/gcc-4_9-branch)
+@@ -0,0 +1,23 @@
++// { dg-options "-std=gnu++11 -O0" }
++// { dg-require-cstdint "" }
++// { dg-require-cmath "" }
++
++#include <ext/random>
++#include <functional>
++
++void
++hyperplot(unsigned int N, unsigned int K, unsigned int n)
++{
++ std::mt19937 re; // the default engine
++ __gnu_cxx::hypergeometric_distribution<> hd(N, K, n);
++ auto gen = std::bind(hd, re);
++ gen();
++}
++
++int
++main()
++{
++ hyperplot(15, 3, 2);
++ hyperplot(500, 50, 30);
++ hyperplot(100, 20, 5);
++}
Index: configure.ac
===================================================================
--- a/src/configure.ac (.../tags/gcc_4_9_1_release)
@@ -306,7 +413,7 @@ Index: gcc/DATESTAMP
+++ b/src/gcc/DATESTAMP (.../branches/gcc-4_9-branch)
@@ -1 +1 @@
-20140716
-+20140728
++20140731
Index: gcc/omp-low.c
===================================================================
--- a/src/gcc/omp-low.c (.../tags/gcc_4_9_1_release)
@@ -2682,6 +2789,10938 @@ Index: libobjc/ChangeLog
2014-07-16 Release Manager
* GCC 4.9.1 released.
+Index: libgfortran/m4/in_pack.m4
+===================================================================
+--- a/src/libgfortran/m4/in_pack.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/in_pack.m4 (.../branches/gcc-4_9-branch)
+@@ -79,7 +79,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = ('rtype_name` *)xmalloc (ssize * sizeof ('rtype_name`));
++ destptr = xmallocarray (ssize, sizeof ('rtype_name`));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/m4/pack.m4
+===================================================================
+--- a/src/libgfortran/m4/pack.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/pack.m4 (.../branches/gcc-4_9-branch)
+@@ -168,8 +168,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof ('rtype_name`) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof ('rtype_name`));
+
+ if (total == 0)
+ return;
+Index: libgfortran/m4/spread.m4
+===================================================================
+--- a/src/libgfortran/m4/spread.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/spread.m4 (.../branches/gcc-4_9-branch)
+@@ -102,8 +102,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof('rtype_name`));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof('rtype_name`));
+ if (rs <= 0)
+ return;
+ }
+@@ -245,7 +245,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof ('rtype_name`));
++ ret->base_addr = xmallocarray (ncopies, sizeof ('rtype_name`));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/m4/transpose.m4
+===================================================================
+--- a/src/libgfortran/m4/transpose.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/transpose.m4 (.../branches/gcc-4_9-branch)
+@@ -61,7 +61,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof ('rtype_name`));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/m4/iforeach.m4
+===================================================================
+--- a/src/libgfortran/m4/iforeach.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/iforeach.m4 (.../branches/gcc-4_9-branch)
+@@ -30,7 +30,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (rtype_name));
+ }
+ else
+ {
+@@ -133,7 +133,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (rtype_name));
+ }
+ else
+ {
+@@ -264,7 +264,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (rtype_name) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (rtype_name));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/m4/eoshift1.m4
+===================================================================
+--- a/src/libgfortran/m4/eoshift1.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/eoshift1.m4 (.../branches/gcc-4_9-branch)
+@@ -106,8 +106,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/m4/eoshift3.m4
+===================================================================
+--- a/src/libgfortran/m4/eoshift3.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/eoshift3.m4 (.../branches/gcc-4_9-branch)
+@@ -90,7 +90,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+@@ -108,8 +108,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/m4/shape.m4
+===================================================================
+--- a/src/libgfortran/m4/shape.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/shape.m4 (.../branches/gcc-4_9-branch)
+@@ -50,7 +50,7 @@
+ {
+ GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
+ ret->offset = 0;
+- ret->base_addr = xmalloc (sizeof ('rtype_name`) * rank);
++ ret->base_addr = xmallocarray (rank, sizeof ('rtype_name`));
+ }
+
+ stride = GFC_DESCRIPTOR_STRIDE(ret,0);
+Index: libgfortran/m4/cshift1.m4
+===================================================================
+--- a/src/libgfortran/m4/cshift1.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/cshift1.m4 (.../branches/gcc-4_9-branch)
+@@ -81,7 +81,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+Index: libgfortran/m4/matmull.m4
+===================================================================
+--- a/src/libgfortran/m4/matmull.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/matmull.m4 (.../branches/gcc-4_9-branch)
+@@ -89,7 +89,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof ('rtype_name`));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/m4/bessel.m4
+===================================================================
+--- a/src/libgfortran/m4/bessel.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/bessel.m4 (.../branches/gcc-4_9-branch)
+@@ -56,7 +56,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof ('rtype_name`) * size);
++ ret->base_addr = xmallocarray (size, sizeof ('rtype_name`));
+ ret->offset = 0;
+ }
+
+@@ -123,7 +123,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof ('rtype_name`) * size);
++ ret->base_addr = xmallocarray (size, sizeof ('rtype_name`));
+ ret->offset = 0;
+ }
+
+Index: libgfortran/m4/unpack.m4
+===================================================================
+--- a/src/libgfortran/m4/unpack.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/unpack.m4 (.../branches/gcc-4_9-branch)
+@@ -100,7 +100,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof ('rtype_name`));
++ ret->base_addr = xmallocarray (rs, sizeof ('rtype_name`));
+ }
+ else
+ {
+@@ -245,7 +245,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof ('rtype_name`));
++ ret->base_addr = xmallocarray (rs, sizeof ('rtype_name`));
+ }
+ else
+ {
+Index: libgfortran/m4/reshape.m4
+===================================================================
+--- a/src/libgfortran/m4/reshape.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/reshape.m4 (.../branches/gcc-4_9-branch)
+@@ -115,11 +115,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof ('rtype_name`);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/m4/ifunction_logical.m4
+===================================================================
+--- a/src/libgfortran/m4/ifunction_logical.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/ifunction_logical.m4 (.../branches/gcc-4_9-branch)
+@@ -89,8 +89,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (rtype_name) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -99,7 +98,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+ }
+ else
+ {
+Index: libgfortran/m4/ifunction.m4
+===================================================================
+--- a/src/libgfortran/m4/ifunction.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/ifunction.m4 (.../branches/gcc-4_9-branch)
+@@ -85,10 +85,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (rtype_name) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -260,8 +259,7 @@
+
+ }
+
+- alloc_size = sizeof (rtype_name) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -273,7 +271,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+
+ }
+ else
+@@ -417,8 +415,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (rtype_name) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -427,7 +424,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+ }
+ else
+ {
+Index: libgfortran/m4/matmul.m4
+===================================================================
+--- a/src/libgfortran/m4/matmul.m4 (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/m4/matmul.m4 (.../branches/gcc-4_9-branch)
+@@ -125,7 +125,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof ('rtype_name`));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/runtime/in_pack_generic.c
+===================================================================
+--- a/src/libgfortran/runtime/in_pack_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/runtime/in_pack_generic.c (.../branches/gcc-4_9-branch)
+@@ -180,7 +180,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = xmalloc (ssize * size);
++ destptr = xmallocarray (ssize, size);
+ dest = (char *)destptr;
+ src = source->base_addr;
+ stride0 = stride[0] * size;
+Index: libgfortran/runtime/memory.c
+===================================================================
+--- a/src/libgfortran/runtime/memory.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/runtime/memory.c (.../branches/gcc-4_9-branch)
+@@ -25,8 +25,13 @@
+
+ #include "libgfortran.h"
+ #include <stdlib.h>
++#include <errno.h>
+
++#ifndef SIZE_MAX
++#define SIZE_MAX ((size_t)-1)
++#endif
+
++
+ void *
+ xmalloc (size_t n)
+ {
+@@ -44,12 +49,34 @@
+ }
+
+
++void *
++xmallocarray (size_t nmemb, size_t size)
++{
++ void *p;
++
++ if (!nmemb || !size)
++ size = nmemb = 1;
++ else if (nmemb > SIZE_MAX / size)
++ {
++ errno = ENOMEM;
++ os_error ("Integer overflow in xmallocarray");
++ }
++
++ p = malloc (nmemb * size);
++
++ if (!p)
++ os_error ("Memory allocation failed in xmallocarray");
++
++ return p;
++}
++
++
+ /* calloc wrapper that aborts on error. */
+
+ void *
+ xcalloc (size_t nmemb, size_t size)
+ {
+- if (nmemb * size == 0)
++ if (!nmemb || !size)
+ nmemb = size = 1;
+
+ void *p = calloc (nmemb, size);
+Index: libgfortran/runtime/convert_char.c
+===================================================================
+--- a/src/libgfortran/runtime/convert_char.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/runtime/convert_char.c (.../branches/gcc-4_9-branch)
+@@ -44,7 +44,7 @@
+ gfc_charlen_type i, l;
+
+ l = len > 0 ? len : 0;
+- *dst = xmalloc ((l + 1) * sizeof (gfc_char4_t));
++ *dst = xmallocarray ((l + 1), sizeof (gfc_char4_t));
+
+ for (i = 0; i < l; i++)
+ (*dst)[i] = src[i];
+@@ -60,7 +60,7 @@
+ gfc_charlen_type i, l;
+
+ l = len > 0 ? len : 0;
+- *dst = xmalloc ((l + 1) * sizeof (unsigned char));
++ *dst = xmalloc (l + 1);
+
+ for (i = 0; i < l; i++)
+ (*dst)[i] = src[i];
+Index: libgfortran/runtime/environ.c
+===================================================================
+--- a/src/libgfortran/runtime/environ.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/runtime/environ.c (.../branches/gcc-4_9-branch)
+@@ -837,7 +837,7 @@
+ }
+ else
+ {
+- elist = xmalloc (unit_count * sizeof (exception_t));
++ elist = xmallocarray (unit_count, sizeof (exception_t));
+ do_count = 0;
+ p = val;
+ do_parse ();
+Index: libgfortran/intrinsics/string_intrinsics_inc.c
+===================================================================
+--- a/src/libgfortran/intrinsics/string_intrinsics_inc.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/string_intrinsics_inc.c (.../branches/gcc-4_9-branch)
+@@ -164,7 +164,7 @@
+ else
+ {
+ /* Allocate space for result string. */
+- *dest = xmalloc (*len * sizeof (CHARTYPE));
++ *dest = xmallocarray (*len, sizeof (CHARTYPE));
+
+ /* Copy string if necessary. */
+ memcpy (*dest, src, *len * sizeof (CHARTYPE));
+@@ -442,7 +442,7 @@
+ *dest = &zero_length_string;
+ else
+ {
+- CHARTYPE *tmp = xmalloc (*rlen * sizeof (CHARTYPE));
++ CHARTYPE *tmp = xmallocarray (*rlen, sizeof (CHARTYPE));
+ memcpy (tmp, res, reslen * sizeof (CHARTYPE));
+ MEMSET (&tmp[reslen], ' ', *rlen - reslen);
+ *dest = tmp;
+Index: libgfortran/intrinsics/pack_generic.c
+===================================================================
+--- a/src/libgfortran/intrinsics/pack_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/pack_generic.c (.../branches/gcc-4_9-branch)
+@@ -152,8 +152,8 @@
+ GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1);
+
+ ret->offset = 0;
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, size);
+
+ if (total == 0)
+ return; /* In this case, nothing remains to be done. */
+@@ -519,7 +519,7 @@
+
+ ret->offset = 0;
+
+- ret->base_addr = xmalloc (size * total);
++ ret->base_addr = xmallocarray (total, size);
+
+ if (total == 0)
+ return;
+Index: libgfortran/intrinsics/transpose_generic.c
+===================================================================
+--- a/src/libgfortran/intrinsics/transpose_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/transpose_generic.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,7 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (size * size0 ((array_t*)ret));
++ ret->base_addr = xmallocarray (size0 ((array_t*)ret), size);
+ ret->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/intrinsics/cshift0.c
+===================================================================
+--- a/src/libgfortran/intrinsics/cshift0.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/cshift0.c (.../branches/gcc-4_9-branch)
+@@ -79,8 +79,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+ }
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/intrinsics/spread_generic.c
+===================================================================
+--- a/src/libgfortran/intrinsics/spread_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/spread_generic.c (.../branches/gcc-4_9-branch)
+@@ -100,7 +100,7 @@
+ GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * size);
++ ret->base_addr = xmallocarray (rs, size);
+
+ if (rs <= 0)
+ return;
+@@ -245,7 +245,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * size);
++ ret->base_addr = xmallocarray (ncopies, size);
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/intrinsics/unpack_generic.c
+===================================================================
+--- a/src/libgfortran/intrinsics/unpack_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/unpack_generic.c (.../branches/gcc-4_9-branch)
+@@ -125,7 +125,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * size);
++ ret->base_addr = xmallocarray (rs, size);
+ }
+ else
+ {
+Index: libgfortran/intrinsics/eoshift0.c
+===================================================================
+--- a/src/libgfortran/intrinsics/eoshift0.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/eoshift0.c (.../branches/gcc-4_9-branch)
+@@ -86,8 +86,8 @@
+
+ }
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/intrinsics/eoshift2.c
+===================================================================
+--- a/src/libgfortran/intrinsics/eoshift2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/eoshift2.c (.../branches/gcc-4_9-branch)
+@@ -78,8 +78,8 @@
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+ {
+Index: libgfortran/intrinsics/reshape_generic.c
+===================================================================
+--- a/src/libgfortran/intrinsics/reshape_generic.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/intrinsics/reshape_generic.c (.../branches/gcc-4_9-branch)
+@@ -99,11 +99,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0; /* xmalloc will allocate 1 byte. */
+ else
+- alloc_size = rs * size;
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, size);
+
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+Index: libgfortran/ChangeLog
+===================================================================
+--- a/src/libgfortran/ChangeLog (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/ChangeLog (.../branches/gcc-4_9-branch)
+@@ -1,3 +1,57 @@
++2014-07-31 Janne Blomqvist <jb@gcc.gnu.org>
++
++ Backport from mainline
++ CVE-2014-5044
++ * libgfortran.h (xmallocarray): New prototype.
++ * runtime/memory.c (xmallocarray): New function.
++ (xcalloc): Check for nonzero separately instead of multiplying.
++ * generated/*.c: Regenerated.
++ * intrinsics/cshift0.c (cshift0): Call xmallocarray instead of
++ xmalloc.
++ * intrinsics/eoshift0.c (eoshift0): Likewise.
++ * intrinsics/eoshift2.c (eoshift2): Likewise.
++ * intrinsics/pack_generic.c (pack_internal): Likewise.
++ (pack_s_internal): Likewise.
++ * intrinsics/reshape_generic.c (reshape_internal): Likewise.
++ * intrinsics/spread_generic.c (spread_internal): Likewise.
++ (spread_internal_scalar): Likewise.
++ * intrinsics/string_intrinsics_inc.c (string_trim): Likewise.
++ (string_minmax): Likewise.
++ * intrinsics/transpose_generic.c (transpose_internal): Likewise.
++ * intrinsics/unpack_generic.c (unpack_internal): Likewise.
++ * io/list_read.c (nml_touch_nodes): Don't cast xmalloc return value.
++ * io/transfer.c (st_set_nml_var): Call xmallocarray instead of
++ xmalloc.
++ * io/unit.c (get_internal_unit): Likewise.
++ (filename_from_unit): Don't cast xmalloc return value.
++ * io/write.c (nml_write_obj): Likewise, formatting.
++ * m4/bessel.m4 (bessel_jn_r'rtype_kind`): Call xmallocarray
++ instead of xmalloc.
++ (besse_yn_r'rtype_kind`): Likewise.
++ * m4/cshift1.m4 (cshift1): Likewise.
++ * m4/eoshift1.m4 (eoshift1): Likewise.
++ * m4/eoshift3.m4 (eoshift3): Likewise.
++ * m4/iforeach.m4: Likewise.
++ * m4/ifunction.m4: Likewise.
++ * m4/ifunction_logical.m4 (name`'rtype_qual`_'atype_code):
++ Likewise.
++ * m4/in_pack.m4 (internal_pack_'rtype_ccode`): Likewise.
++ * m4/matmul.m4 (matmul_'rtype_code`): Likewise.
++ * m4/matmull.m4 (matmul_'rtype_code`): Likewise.
++ * m4/pack.m4 (pack_'rtype_code`): Likewise.
++ * m4/reshape.m4 (reshape_'rtype_ccode`): Likewise.
++ * m4/shape.m4 (shape_'rtype_kind`): Likewise.
++ * m4/spread.m4 (spread_'rtype_code`): Likewise.
++ (spread_scalar_'rtype_code`): Likewise.
++ * m4/transpose.m4 (transpose_'rtype_code`): Likewise.
++ * m4/unpack.m4 (unpack0_'rtype_code`): Likewise.
++ (unpack1_'rtype_code`): Likewise.
++ * runtime/convert_char.c (convert_char1_to_char4): Likewise.
++ (convert_char4_to_char1): Simplify.
++ * runtime/environ.c (init_unformatted): Call xmallocarray instead
++ of xmalloc.
++ * runtime/in_pack_generic.c (internal_pack): Likewise.
++
+ 2014-07-16 Release Manager
+
+ * GCC 4.9.1 released.
+Index: libgfortran/generated/spread_r10.c
+===================================================================
+--- a/src/libgfortran/generated/spread_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_r10.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_REAL_10));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_REAL_10));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_REAL_10));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_REAL_10));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxloc1_4_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/norm2_r4.c
+===================================================================
+--- a/src/libgfortran/generated/norm2_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/norm2_r4.c (.../branches/gcc-4_9-branch)
+@@ -101,10 +101,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/parity_l2.c
+===================================================================
+--- a/src/libgfortran/generated/parity_l2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/parity_l2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/eoshift3_4.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift3_4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift3_4.c (.../branches/gcc-4_9-branch)
+@@ -89,7 +89,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+@@ -107,8 +107,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/transpose_c8.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_c8.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_8) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_COMPLEX_8));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/eoshift1_8.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift1_8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift1_8.c (.../branches/gcc-4_9-branch)
+@@ -105,8 +105,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/reshape_r16.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_r16.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_REAL_16);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/bessel_r4.c
+===================================================================
+--- a/src/libgfortran/generated/bessel_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/bessel_r4.c (.../branches/gcc-4_9-branch)
+@@ -55,7 +55,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_4) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_4));
+ ret->offset = 0;
+ }
+
+@@ -122,7 +122,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_4) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_4));
+ ret->offset = 0;
+ }
+
+Index: libgfortran/generated/any_l2.c
+===================================================================
+--- a/src/libgfortran/generated/any_l2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/any_l2.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_2));
+ }
+ else
+ {
+Index: libgfortran/generated/product_r4.c
+===================================================================
+--- a/src/libgfortran/generated/product_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_r4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/iany_i1.c
+===================================================================
+--- a/src/libgfortran/generated/iany_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iany_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/parity_l16.c
+===================================================================
+--- a/src/libgfortran/generated/parity_l16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/parity_l16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/in_pack_r4.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_r4.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_REAL_4 *)xmalloc (ssize * sizeof (GFC_REAL_4));
++ destptr = xmallocarray (ssize, sizeof (GFC_REAL_4));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/product_i2.c
+===================================================================
+--- a/src/libgfortran/generated/product_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/iparity_i4.c
+===================================================================
+--- a/src/libgfortran/generated/iparity_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iparity_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_4_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/reshape_c4.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_c4.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_COMPLEX_4);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/maxloc0_4_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/iall_i8.c
+===================================================================
+--- a/src/libgfortran/generated/iall_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iall_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_r16.c
+===================================================================
+--- a/src/libgfortran/generated/sum_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_r16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_i1.c
+===================================================================
+--- a/src/libgfortran/generated/sum_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_i2.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_i2.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_INTEGER_2 *)xmalloc (ssize * sizeof (GFC_INTEGER_2));
++ destptr = xmallocarray (ssize, sizeof (GFC_INTEGER_2));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/transpose_r10.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_r10.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_10) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_REAL_10));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_16_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_16_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_i1.c
+===================================================================
+--- a/src/libgfortran/generated/spread_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_i1.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_INTEGER_1));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_1));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_INTEGER_1));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_1));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxloc0_16_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxval_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_r16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/product_c10.c
+===================================================================
+--- a/src/libgfortran/generated/product_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_c10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_r16.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_r16.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_REAL_16) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_REAL_16));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc0_4_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/iany_i2.c
+===================================================================
+--- a/src/libgfortran/generated/iany_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iany_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_r4.c
+===================================================================
+--- a/src/libgfortran/generated/sum_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_r4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_c8.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_c8.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_8));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_8));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_c16.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_c16.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_COMPLEX_16 *)xmalloc (ssize * sizeof (GFC_COMPLEX_16));
++ destptr = xmallocarray (ssize, sizeof (GFC_COMPLEX_16));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/minloc0_4_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/spread_c10.c
+===================================================================
+--- a/src/libgfortran/generated/spread_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_c10.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_COMPLEX_10));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_COMPLEX_10));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_COMPLEX_10));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_COMPLEX_10));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxloc0_8_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/spread_r4.c
+===================================================================
+--- a/src/libgfortran/generated/spread_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_r4.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_REAL_4));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_REAL_4));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_REAL_4));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_REAL_4));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/minloc0_8_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_c8.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_c8.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_COMPLEX_8) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_8));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc1_16_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_i2.c
+===================================================================
+--- a/src/libgfortran/generated/sum_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/iparity_i16.c
+===================================================================
+--- a/src/libgfortran/generated/iparity_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iparity_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/reshape_c16.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_c16.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_COMPLEX_16);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/pack_c4.c
+===================================================================
+--- a/src/libgfortran/generated/pack_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_c4.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_4) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_COMPLEX_4));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/parity_l4.c
+===================================================================
+--- a/src/libgfortran/generated/parity_l4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/parity_l4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/spread_i2.c
+===================================================================
+--- a/src/libgfortran/generated/spread_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_i2.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_INTEGER_2));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_2));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_INTEGER_2));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_2));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/any_l4.c
+===================================================================
+--- a/src/libgfortran/generated/any_l4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/any_l4.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_4_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_8_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_4_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_4_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc0_8_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_8_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/product_i4.c
+===================================================================
+--- a/src/libgfortran/generated/product_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_c16.c
+===================================================================
+--- a/src/libgfortran/generated/sum_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_c16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+ }
+ else
+ {
+Index: libgfortran/generated/transpose_c10.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_c10.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_10) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_COMPLEX_10));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_16_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/transpose_r4.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_r4.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_4) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_REAL_4));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/cshift1_4.c
+===================================================================
+--- a/src/libgfortran/generated/cshift1_4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/cshift1_4.c (.../branches/gcc-4_9-branch)
+@@ -80,7 +80,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+Index: libgfortran/generated/maxloc0_8_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/count_8_l.c
+===================================================================
+--- a/src/libgfortran/generated/count_8_l.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/count_8_l.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_i4.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_i4.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_INTEGER_4 *)xmalloc (ssize * sizeof (GFC_INTEGER_4));
++ destptr = xmallocarray (ssize, sizeof (GFC_INTEGER_4));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/minloc0_16_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_8_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/matmul_c16.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_c16.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_COMPLEX_16) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_16));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minval_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minval_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/shape_i16.c
+===================================================================
+--- a/src/libgfortran/generated/shape_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/shape_i16.c (.../branches/gcc-4_9-branch)
+@@ -49,7 +49,7 @@
+ {
+ GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
+ ret->offset = 0;
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ ret->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+
+ stride = GFC_DESCRIPTOR_STRIDE(ret,0);
+Index: libgfortran/generated/iany_i4.c
+===================================================================
+--- a/src/libgfortran/generated/iany_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iany_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/product_i16.c
+===================================================================
+--- a/src/libgfortran/generated/product_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_i1.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_i1.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_1));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_1));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_4_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_i1.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_i1.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_INTEGER_1) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_INTEGER_1));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minval_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minval_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_r4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_i16.c
+===================================================================
+--- a/src/libgfortran/generated/spread_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_i16.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_INTEGER_16));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_16));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_INTEGER_16));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_16));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/sum_i4.c
+===================================================================
+--- a/src/libgfortran/generated/sum_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_r10.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_r10.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_10));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_10));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+Index: libgfortran/generated/bessel_r16.c
+===================================================================
+--- a/src/libgfortran/generated/bessel_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/bessel_r16.c (.../branches/gcc-4_9-branch)
+@@ -59,7 +59,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_16) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_16));
+ ret->offset = 0;
+ }
+
+@@ -126,7 +126,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_16) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_16));
+ ret->offset = 0;
+ }
+
+Index: libgfortran/generated/norm2_r8.c
+===================================================================
+--- a/src/libgfortran/generated/norm2_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/norm2_r8.c (.../branches/gcc-4_9-branch)
+@@ -101,10 +101,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/spread_i4.c
+===================================================================
+--- a/src/libgfortran/generated/spread_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_i4.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_INTEGER_4));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_4));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_INTEGER_4));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_4));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/eoshift3_8.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift3_8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift3_8.c (.../branches/gcc-4_9-branch)
+@@ -89,7 +89,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+@@ -107,8 +107,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc1_4_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minval_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minval_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/bessel_r8.c
+===================================================================
+--- a/src/libgfortran/generated/bessel_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/bessel_r8.c (.../branches/gcc-4_9-branch)
+@@ -55,7 +55,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_8) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_8));
+ ret->offset = 0;
+ }
+
+@@ -122,7 +122,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_8) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_8));
+ ret->offset = 0;
+ }
+
+Index: libgfortran/generated/unpack_r4.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_r4.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/product_r8.c
+===================================================================
+--- a/src/libgfortran/generated/product_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_r8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/matmul_r4.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_r4.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_REAL_4) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_REAL_4));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/unpack_i2.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_i2.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_2));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_2));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_r8.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_r8.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_REAL_8 *)xmalloc (ssize * sizeof (GFC_REAL_8));
++ destptr = xmallocarray (ssize, sizeof (GFC_REAL_8));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/maxloc1_4_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_8_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/reshape_c8.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_c8.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_COMPLEX_8);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/iparity_i8.c
+===================================================================
+--- a/src/libgfortran/generated/iparity_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iparity_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/count_1_l.c
+===================================================================
+--- a/src/libgfortran/generated/count_1_l.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/count_1_l.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_8_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_i2.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_i2.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_INTEGER_2) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_INTEGER_2));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc1_4_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/transpose_i16.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_i16.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_INTEGER_16));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc0_16_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/transpose_i4.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_i4.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_INTEGER_4));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_16_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_4_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/matmul_l16.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_l16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_l16.c (.../branches/gcc-4_9-branch)
+@@ -88,7 +88,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_LOGICAL_16) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_LOGICAL_16));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/maxloc1_8_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_4_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/product_r16.c
+===================================================================
+--- a/src/libgfortran/generated/product_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_r16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_r8.c
+===================================================================
+--- a/src/libgfortran/generated/sum_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_r8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/norm2_r10.c
+===================================================================
+--- a/src/libgfortran/generated/norm2_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/norm2_r10.c (.../branches/gcc-4_9-branch)
+@@ -101,10 +101,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/unpack_c10.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_c10.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_10));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_10));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_10));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_10));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_r8.c
+===================================================================
+--- a/src/libgfortran/generated/spread_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_r8.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_REAL_8));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_REAL_8));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_REAL_8));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_REAL_8));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/minloc1_16_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_16_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_r16.c
+===================================================================
+--- a/src/libgfortran/generated/spread_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_r16.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_REAL_16));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_REAL_16));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_REAL_16));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_REAL_16));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/pack_c8.c
+===================================================================
+--- a/src/libgfortran/generated/pack_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_c8.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_8) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_COMPLEX_8));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/minval_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minval_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_r10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+Index: libgfortran/generated/parity_l8.c
+===================================================================
+--- a/src/libgfortran/generated/parity_l8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/parity_l8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/minval_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minval_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/any_l8.c
+===================================================================
+--- a/src/libgfortran/generated/any_l8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/any_l8.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_16_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc0_4_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc0_8_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_4_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_8_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/unpack_i4.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_i4.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_16_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/product_i8.c
+===================================================================
+--- a/src/libgfortran/generated/product_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/count_2_l.c
+===================================================================
+--- a/src/libgfortran/generated/count_2_l.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/count_2_l.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/transpose_r8.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_r8.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_8) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_REAL_8));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/cshift1_8.c
+===================================================================
+--- a/src/libgfortran/generated/cshift1_8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/cshift1_8.c (.../branches/gcc-4_9-branch)
+@@ -80,7 +80,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+Index: libgfortran/generated/matmul_i4.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_i4.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_INTEGER_4) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_INTEGER_4));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/pack_r10.c
+===================================================================
+--- a/src/libgfortran/generated/pack_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_r10.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_10) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_REAL_10));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/minloc1_16_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_i8.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_i8.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_INTEGER_8 *)xmalloc (ssize * sizeof (GFC_INTEGER_8));
++ destptr = xmallocarray (ssize, sizeof (GFC_INTEGER_8));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/transpose_r16.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_r16.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_16) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_REAL_16));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_4_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxval_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/product_c16.c
+===================================================================
+--- a/src/libgfortran/generated/product_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_c16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_16));
+ }
+ else
+ {
+Index: libgfortran/generated/reshape_r4.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_r4.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_REAL_4);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/iany_i8.c
+===================================================================
+--- a/src/libgfortran/generated/iany_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iany_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/cshift1_16.c
+===================================================================
+--- a/src/libgfortran/generated/cshift1_16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/cshift1_16.c (.../branches/gcc-4_9-branch)
+@@ -80,7 +80,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+Index: libgfortran/generated/maxloc0_4_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc0_4_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/spread_c16.c
+===================================================================
+--- a/src/libgfortran/generated/spread_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_c16.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_COMPLEX_16));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_COMPLEX_16));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_COMPLEX_16));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_COMPLEX_16));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxval_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_r4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minval_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minval_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_r8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_16_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_i16.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_i16.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_i8.c
+===================================================================
+--- a/src/libgfortran/generated/sum_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/pack_i1.c
+===================================================================
+--- a/src/libgfortran/generated/pack_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_i1.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_1) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_INTEGER_1));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/any_l16.c
+===================================================================
+--- a/src/libgfortran/generated/any_l16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/any_l16.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_i8.c
+===================================================================
+--- a/src/libgfortran/generated/spread_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_i8.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_INTEGER_8));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_INTEGER_8));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_INTEGER_8));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_INTEGER_8));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxval_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_r8.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_r8.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_4_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/all_l1.c
+===================================================================
+--- a/src/libgfortran/generated/all_l1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/all_l1.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_1));
+ }
+ else
+ {
+Index: libgfortran/generated/matmul_r8.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_r8.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_REAL_8) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_REAL_8));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc0_4_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_4_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_4_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc0_4_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_8_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/pack_c10.c
+===================================================================
+--- a/src/libgfortran/generated/pack_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_c10.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_10) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_COMPLEX_10));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/pack_r4.c
+===================================================================
+--- a/src/libgfortran/generated/pack_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_r4.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_4) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_REAL_4));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/transpose_c16.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_c16.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_16) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_COMPLEX_16));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc0_8_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_4_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_16_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/pack_i2.c
+===================================================================
+--- a/src/libgfortran/generated/pack_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_i2.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_2) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_INTEGER_2));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/transpose_i8.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_i8.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_INTEGER_8));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/eoshift1_16.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift1_16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift1_16.c (.../branches/gcc-4_9-branch)
+@@ -105,8 +105,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/all_l2.c
+===================================================================
+--- a/src/libgfortran/generated/all_l2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/all_l2.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_2));
+ }
+ else
+ {
+Index: libgfortran/generated/product_c4.c
+===================================================================
+--- a/src/libgfortran/generated/product_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_c4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+ }
+ else
+ {
+Index: libgfortran/generated/iall_i1.c
+===================================================================
+--- a/src/libgfortran/generated/iall_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iall_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/reshape_i4.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_i4.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_INTEGER_4);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/in_pack_r10.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_r10.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_REAL_10 *)xmalloc (ssize * sizeof (GFC_REAL_10));
++ destptr = xmallocarray (ssize, sizeof (GFC_REAL_10));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/in_pack_c4.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_c4.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_COMPLEX_4 *)xmalloc (ssize * sizeof (GFC_COMPLEX_4));
++ destptr = xmallocarray (ssize, sizeof (GFC_COMPLEX_4));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/all_l16.c
+===================================================================
+--- a/src/libgfortran/generated/all_l16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/all_l16.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_16_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_8_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minval_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minval_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/reshape_r10.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_r10.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_REAL_10);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/unpack_r16.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_r16.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_REAL_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxval_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minval_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minval_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_16_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/shape_i4.c
+===================================================================
+--- a/src/libgfortran/generated/shape_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/shape_i4.c (.../branches/gcc-4_9-branch)
+@@ -49,7 +49,7 @@
+ {
+ GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
+ ret->offset = 0;
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ ret->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+
+ stride = GFC_DESCRIPTOR_STRIDE(ret,0);
+Index: libgfortran/generated/minloc1_4_i16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_4_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc0_8_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/iall_i2.c
+===================================================================
+--- a/src/libgfortran/generated/iall_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iall_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_16_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc0_8_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_i1.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/minloc1_16_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_r8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/unpack_i8.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_i8.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_INTEGER_8));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_4_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/count_4_l.c
+===================================================================
+--- a/src/libgfortran/generated/count_4_l.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/count_4_l.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_r10.c
+===================================================================
+--- a/src/libgfortran/generated/sum_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_r10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_c4.c
+===================================================================
+--- a/src/libgfortran/generated/sum_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_c4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_16_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/pack_i16.c
+===================================================================
+--- a/src/libgfortran/generated/pack_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_i16.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_INTEGER_16));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/matmul_i8.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_i8.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_INTEGER_8) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_INTEGER_8));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/maxloc0_16_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/spread_c4.c
+===================================================================
+--- a/src/libgfortran/generated/spread_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_c4.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_COMPLEX_4));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_COMPLEX_4));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_COMPLEX_4));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_COMPLEX_4));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/maxval_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_r10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+Index: libgfortran/generated/pack_i4.c
+===================================================================
+--- a/src/libgfortran/generated/pack_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_i4.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_INTEGER_4));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/maxloc1_4_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/matmul_r10.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_r10.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_REAL_10) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_REAL_10));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minloc1_4_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_8_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_r4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_l4.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_l4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_l4.c (.../branches/gcc-4_9-branch)
+@@ -88,7 +88,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_LOGICAL_4) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_LOGICAL_4));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/reshape_r8.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_r8.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_REAL_8);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/in_pack_c10.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_c10.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_COMPLEX_10 *)xmalloc (ssize * sizeof (GFC_COMPLEX_10));
++ destptr = xmallocarray (ssize, sizeof (GFC_COMPLEX_10));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/all_l4.c
+===================================================================
+--- a/src/libgfortran/generated/all_l4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/all_l4.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_8_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_i2.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/norm2_r16.c
+===================================================================
+--- a/src/libgfortran/generated/norm2_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/norm2_r16.c (.../branches/gcc-4_9-branch)
+@@ -105,10 +105,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/reshape_c10.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_c10.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_COMPLEX_10);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/unpack_c16.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_c16.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_16));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_16));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_4_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxval_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_r8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/transpose_c4.c
+===================================================================
+--- a/src/libgfortran/generated/transpose_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/transpose_c4.c (.../branches/gcc-4_9-branch)
+@@ -60,7 +60,8 @@
+ GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
+ GFC_DESCRIPTOR_EXTENT(source, 1));
+
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_4) * size0 ((array_t *) ret));
++ ret->base_addr = xmallocarray (size0 ((array_t *) ret),
++ sizeof (GFC_COMPLEX_4));
+ ret->offset = 0;
+ } else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/eoshift1_4.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift1_4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift1_4.c (.../branches/gcc-4_9-branch)
+@@ -105,8 +105,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/minval_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minval_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minval_r16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_16));
+ }
+ else
+ {
+Index: libgfortran/generated/iany_i16.c
+===================================================================
+--- a/src/libgfortran/generated/iany_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iany_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_4_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_4_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc0_16_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/sum_c10.c
+===================================================================
+--- a/src/libgfortran/generated/sum_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_c10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_10));
+ }
+ else
+ {
+Index: libgfortran/generated/iall_i4.c
+===================================================================
+--- a/src/libgfortran/generated/iall_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iall_i4.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_4_r16.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_4_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_4_r16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_8_r16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_8_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_8_r16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/pack_r8.c
+===================================================================
+--- a/src/libgfortran/generated/pack_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_r8.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_8) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_REAL_8));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/matmul_c10.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_c10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_c10.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_COMPLEX_10) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_10));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/maxloc0_16_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/pack_r16.c
+===================================================================
+--- a/src/libgfortran/generated/pack_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_r16.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_16) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_REAL_16));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/minloc1_16_i8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_16_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_16_i8.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_16_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_16_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_16_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/unpack_c4.c
+===================================================================
+--- a/src/libgfortran/generated/unpack_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/unpack_c4.c (.../branches/gcc-4_9-branch)
+@@ -99,7 +99,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_4));
+ }
+ else
+ {
+@@ -244,7 +244,7 @@
+ rs *= extent[n];
+ }
+ ret->offset = 0;
+- ret->base_addr = xmalloc (rs * sizeof (GFC_COMPLEX_4));
++ ret->base_addr = xmallocarray (rs, sizeof (GFC_COMPLEX_4));
+ }
+ else
+ {
+Index: libgfortran/generated/iparity_i1.c
+===================================================================
+--- a/src/libgfortran/generated/iparity_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iparity_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/product_c8.c
+===================================================================
+--- a/src/libgfortran/generated/product_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_c8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_i16.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_i16.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_INTEGER_16 *)xmalloc (ssize * sizeof (GFC_INTEGER_16));
++ destptr = xmallocarray (ssize, sizeof (GFC_INTEGER_16));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/minloc0_8_i4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_i4.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_c4.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_c4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_c4.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_COMPLEX_4) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_4));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/reshape_i8.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_i8.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_INTEGER_8);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/in_pack_c8.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_c8.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_COMPLEX_8 *)xmalloc (ssize * sizeof (GFC_COMPLEX_8));
++ destptr = xmallocarray (ssize, sizeof (GFC_COMPLEX_8));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/bessel_r10.c
+===================================================================
+--- a/src/libgfortran/generated/bessel_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/bessel_r10.c (.../branches/gcc-4_9-branch)
+@@ -55,7 +55,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_10) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_10));
+ ret->offset = 0;
+ }
+
+@@ -122,7 +122,7 @@
+ {
+ size_t size = n2 < n1 ? 0 : n2-n1+1;
+ GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
+- ret->base_addr = xmalloc (sizeof (GFC_REAL_10) * size);
++ ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_10));
+ ret->offset = 0;
+ }
+
+Index: libgfortran/generated/iall_i16.c
+===================================================================
+--- a/src/libgfortran/generated/iall_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iall_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_16_i1.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/reshape_i16.c
+===================================================================
+--- a/src/libgfortran/generated/reshape_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/reshape_i16.c (.../branches/gcc-4_9-branch)
+@@ -111,11 +111,11 @@
+ ret->offset = 0;
+
+ if (unlikely (rs < 1))
+- alloc_size = 1;
++ alloc_size = 0;
+ else
+- alloc_size = rs * sizeof (GFC_INTEGER_16);
++ alloc_size = rs;
+
+- ret->base_addr = xmalloc (alloc_size);
++ ret->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim;
+ }
+
+Index: libgfortran/generated/count_16_l.c
+===================================================================
+--- a/src/libgfortran/generated/count_16_l.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/count_16_l.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_i1.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_i1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_4_i4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_i4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_i4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxval_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_i8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/eoshift3_16.c
+===================================================================
+--- a/src/libgfortran/generated/eoshift3_16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/eoshift3_16.c (.../branches/gcc-4_9-branch)
+@@ -89,7 +89,7 @@
+ {
+ int i;
+
+- ret->base_addr = xmalloc (size * arraysize);
++ ret->base_addr = xmallocarray (arraysize, size);
+ ret->offset = 0;
+ ret->dtype = array->dtype;
+ for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+@@ -107,8 +107,8 @@
+ GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
+
+ }
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (size * arraysize);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (arraysize, size);
+
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/shape_i8.c
+===================================================================
+--- a/src/libgfortran/generated/shape_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/shape_i8.c (.../branches/gcc-4_9-branch)
+@@ -49,7 +49,7 @@
+ {
+ GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
+ ret->offset = 0;
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ ret->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+
+ stride = GFC_DESCRIPTOR_STRIDE(ret,0);
+Index: libgfortran/generated/maxloc0_4_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_i16.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/maxloc1_4_r10.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_4_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_4_r10.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_4) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_8_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_8_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_8_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_8_r10.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_r10.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/iparity_i2.c
+===================================================================
+--- a/src/libgfortran/generated/iparity_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/iparity_i2.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_2) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_2));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_16_r4.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_16_r8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_16_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_16_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_16) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_16));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/sum_i16.c
+===================================================================
+--- a/src/libgfortran/generated/sum_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc0_4_i8.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc0_4_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc0_4_i8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_4) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_4));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/pack_c16.c
+===================================================================
+--- a/src/libgfortran/generated/pack_c16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_c16.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_COMPLEX_16) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_COMPLEX_16));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/maxloc1_16_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_i16.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_r4.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_r4.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_r4.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/sum_c8.c
+===================================================================
+--- a/src/libgfortran/generated/sum_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/sum_c8.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_COMPLEX_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_COMPLEX_8));
+ }
+ else
+ {
+Index: libgfortran/generated/maxloc1_16_i2.c
+===================================================================
+--- a/src/libgfortran/generated/maxloc1_16_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxloc1_16_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/parity_l1.c
+===================================================================
+--- a/src/libgfortran/generated/parity_l1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/parity_l1.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+Index: libgfortran/generated/maxval_i16.c
+===================================================================
+--- a/src/libgfortran/generated/maxval_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/maxval_i16.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -286,8 +285,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -299,7 +297,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+
+ }
+ else
+@@ -472,8 +470,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_16) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -482,7 +479,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_16));
+ }
+ else
+ {
+Index: libgfortran/generated/spread_c8.c
+===================================================================
+--- a/src/libgfortran/generated/spread_c8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/spread_c8.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,8 @@
+ }
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (rs * sizeof(GFC_COMPLEX_8));
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (rs, sizeof(GFC_COMPLEX_8));
+ if (rs <= 0)
+ return;
+ }
+@@ -244,7 +244,7 @@
+
+ if (ret->base_addr == NULL)
+ {
+- ret->base_addr = xmalloc (ncopies * sizeof (GFC_COMPLEX_8));
++ ret->base_addr = xmallocarray (ncopies, sizeof (GFC_COMPLEX_8));
+ ret->offset = 0;
+ GFC_DIMENSION_SET(ret->dim[0], 0, ncopies - 1, 1);
+ }
+Index: libgfortran/generated/matmul_i16.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_i16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_i16.c (.../branches/gcc-4_9-branch)
+@@ -124,7 +124,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_INTEGER_16) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_INTEGER_16));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/pack_i8.c
+===================================================================
+--- a/src/libgfortran/generated/pack_i8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/pack_i8.c (.../branches/gcc-4_9-branch)
+@@ -167,8 +167,8 @@
+
+ ret->offset = 0;
+
+- /* xmalloc allocates a single byte for zero size. */
+- ret->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * total);
++ /* xmallocarray allocates a single byte for zero size. */
++ ret->base_addr = xmallocarray (total, sizeof (GFC_INTEGER_8));
+
+ if (total == 0)
+ return;
+Index: libgfortran/generated/any_l1.c
+===================================================================
+--- a/src/libgfortran/generated/any_l1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/any_l1.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_1));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc1_8_i2.c
+===================================================================
+--- a/src/libgfortran/generated/minloc1_8_i2.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc1_8_i2.c (.../branches/gcc-4_9-branch)
+@@ -98,10 +98,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -294,8 +293,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -307,7 +305,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+
+ }
+ else
+@@ -485,8 +483,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -495,7 +492,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+Index: libgfortran/generated/minloc0_8_r8.c
+===================================================================
+--- a/src/libgfortran/generated/minloc0_8_r8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/minloc0_8_r8.c (.../branches/gcc-4_9-branch)
+@@ -58,7 +58,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -199,7 +199,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank - 1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else
+ {
+@@ -367,7 +367,7 @@
+ GFC_DIMENSION_SET(retarray->dim[0], 0, rank-1, 1);
+ retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
+ retarray->offset = 0;
+- retarray->base_addr = xmalloc (sizeof (GFC_INTEGER_8) * rank);
++ retarray->base_addr = xmallocarray (rank, sizeof (GFC_INTEGER_8));
+ }
+ else if (unlikely (compile_options.bounds_check))
+ {
+Index: libgfortran/generated/matmul_l8.c
+===================================================================
+--- a/src/libgfortran/generated/matmul_l8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/matmul_l8.c (.../branches/gcc-4_9-branch)
+@@ -88,7 +88,7 @@
+ }
+
+ retarray->base_addr
+- = xmalloc (sizeof (GFC_LOGICAL_8) * size0 ((array_t *) retarray));
++ = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_LOGICAL_8));
+ retarray->offset = 0;
+ }
+ else if (unlikely (compile_options.bounds_check))
+Index: libgfortran/generated/product_r10.c
+===================================================================
+--- a/src/libgfortran/generated/product_r10.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_r10.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_REAL_10));
+ }
+ else
+ {
+Index: libgfortran/generated/product_i1.c
+===================================================================
+--- a/src/libgfortran/generated/product_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/product_i1.c (.../branches/gcc-4_9-branch)
+@@ -97,10 +97,9 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+@@ -272,8 +271,7 @@
+
+ }
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+@@ -285,7 +283,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+
+ }
+ else
+@@ -430,8 +428,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_INTEGER_1) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -440,7 +437,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_INTEGER_1));
+ }
+ else
+ {
+Index: libgfortran/generated/all_l8.c
+===================================================================
+--- a/src/libgfortran/generated/all_l8.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/all_l8.c (.../branches/gcc-4_9-branch)
+@@ -101,8 +101,7 @@
+ retarray->offset = 0;
+ retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+- alloc_size = sizeof (GFC_LOGICAL_8) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
+- * extent[rank-1];
++ alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+@@ -111,7 +110,7 @@
+ return;
+ }
+ else
+- retarray->base_addr = xmalloc (alloc_size);
++ retarray->base_addr = xmallocarray (alloc_size, sizeof (GFC_LOGICAL_8));
+ }
+ else
+ {
+Index: libgfortran/generated/in_pack_r16.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_r16.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_r16.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_REAL_16 *)xmalloc (ssize * sizeof (GFC_REAL_16));
++ destptr = xmallocarray (ssize, sizeof (GFC_REAL_16));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/generated/in_pack_i1.c
+===================================================================
+--- a/src/libgfortran/generated/in_pack_i1.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/generated/in_pack_i1.c (.../branches/gcc-4_9-branch)
+@@ -76,7 +76,7 @@
+ return source->base_addr;
+
+ /* Allocate storage for the destination. */
+- destptr = (GFC_INTEGER_1 *)xmalloc (ssize * sizeof (GFC_INTEGER_1));
++ destptr = xmallocarray (ssize, sizeof (GFC_INTEGER_1));
+ dest = destptr;
+ src = source->base_addr;
+ stride0 = stride[0];
+Index: libgfortran/libgfortran.h
+===================================================================
+--- a/src/libgfortran/libgfortran.h (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/libgfortran.h (.../branches/gcc-4_9-branch)
+@@ -768,6 +768,9 @@
+ extern void *xmalloc (size_t) __attribute__ ((malloc));
+ internal_proto(xmalloc);
+
++extern void *xmallocarray (size_t, size_t) __attribute__ ((malloc));
++internal_proto(xmallocarray);
++
+ extern void *xcalloc (size_t, size_t) __attribute__ ((malloc));
+ internal_proto(xcalloc);
+
+Index: libgfortran/io/list_read.c
+===================================================================
+--- a/src/libgfortran/io/list_read.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/io/list_read.c (.../branches/gcc-4_9-branch)
+@@ -2407,7 +2407,7 @@
+ {
+ index_type len = strlen (nl->var_name) + 1;
+ int dim;
+- char * ext_name = (char*)xmalloc (len + 1);
++ char * ext_name = xmalloc (len + 1);
+ memcpy (ext_name, nl->var_name, len-1);
+ memcpy (ext_name + len - 1, "%", 2);
+ for (nl = nl->next; nl; nl = nl->next)
+Index: libgfortran/io/unit.c
+===================================================================
+--- a/src/libgfortran/io/unit.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/io/unit.c (.../branches/gcc-4_9-branch)
+@@ -454,7 +454,7 @@
+ {
+ iunit->rank = GFC_DESCRIPTOR_RANK (dtp->internal_unit_desc);
+ iunit->ls = (array_loop_spec *)
+- xmalloc (iunit->rank * sizeof (array_loop_spec));
++ xmallocarray (iunit->rank, sizeof (array_loop_spec));
+ dtp->internal_unit_len *=
+ init_loop_spec (dtp->internal_unit_desc, iunit->ls, &start_record);
+
+Index: libgfortran/io/transfer.c
+===================================================================
+--- a/src/libgfortran/io/transfer.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/io/transfer.c (.../branches/gcc-4_9-branch)
+@@ -3786,9 +3786,9 @@
+ if (nml->var_rank > 0)
+ {
+ nml->dim = (descriptor_dimension*)
+- xmalloc (nml->var_rank * sizeof (descriptor_dimension));
++ xmallocarray (nml->var_rank, sizeof (descriptor_dimension));
+ nml->ls = (array_loop_spec*)
+- xmalloc (nml->var_rank * sizeof (array_loop_spec));
++ xmallocarray (nml->var_rank, sizeof (array_loop_spec));
+ }
+ else
+ {
+Index: libgfortran/io/write.c
+===================================================================
+--- a/src/libgfortran/io/write.c (.../tags/gcc_4_9_1_release)
++++ b/src/libgfortran/io/write.c (.../branches/gcc-4_9-branch)
+@@ -1864,7 +1864,7 @@
+ base_var_name_len = base ? strlen (base->var_name) : 0;
+ ext_name_len = base_name_len + base_var_name_len
+ + strlen (obj->var_name) + obj->var_rank * NML_DIGITS + 1;
+- ext_name = (char*)xmalloc (ext_name_len);
++ ext_name = xmalloc (ext_name_len);
+
+ memcpy (ext_name, base_name, base_name_len);
+ clen = strlen (obj->var_name + base_var_name_len);
+@@ -1893,7 +1893,7 @@
+ /* Now obj_name. */
+
+ obj_name_len = strlen (obj->var_name) + 1;
+- obj_name = xmalloc (obj_name_len+1);
++ obj_name = xmalloc (obj_name_len + 1);
+ memcpy (obj_name, obj->var_name, obj_name_len-1);
+ memcpy (obj_name + obj_name_len-1, "%", 2);
+
Index: .
===================================================================
--- a/src/. (.../tags/gcc_4_9_1_release)