===================================================================
@@ -45,6 +45,7 @@ internal_pack_'rtype_ccode` ('rtype` * source)
index_type stride0;
index_type dim;
index_type ssize;
+ index_type alloc_size;
const 'rtype_name` *src;
'rtype_name` * restrict dest;
'rtype_name` *destptr;
@@ -79,7 +80,12 @@ internal_pack_'rtype_ccode` ('rtype` * source)
return source->data;
/* Allocate storage for the destination. */
- destptr = ('rtype_name` *)internal_malloc_size (ssize * sizeof ('rtype_name`));
+ if (unlikely (ssize < 1))
+ alloc_size = 1;
+ else
+ alloc_size = ssize * sizeof ('rtype_name`);
+
+ destptr = ('rtype_name` *)internal_malloc_size (alloc_size);
dest = destptr;
src = source->data;
stride0 = stride[0];
===================================================================
@@ -52,6 +52,8 @@ transpose_'rtype_code` ('rtype` * const restrict r
if (ret->data == NULL)
{
+ index_type alloc_size, array_size;
+
assert (GFC_DESCRIPTOR_RANK (ret) == 2);
assert (ret->dtype == source->dtype);
@@ -61,7 +63,13 @@ transpose_'rtype_code` ('rtype` * const restrict r
GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
GFC_DESCRIPTOR_EXTENT(source, 1));
- ret->data = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) ret));
+ array_size = size0 ((array_t *) ret);
+ if (unlikely (array_size < 1))
+ alloc_size = 1;
+ else
+ alloc_size = sizeof ('rtype_name`) * array_size;
+
+ ret->data = internal_malloc_size (alloc_size);
ret->offset = 0;
} else if (unlikely (compile_options.bounds_check))
{
===================================================================
@@ -89,7 +89,6 @@ eoshift1 (gfc_array_char * const restrict ret,
{
int i;
- ret->data = internal_malloc_size (size * arraysize);
ret->offset = 0;
ret->dtype = array->dtype;
for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
@@ -107,7 +106,7 @@ eoshift1 (gfc_array_char * const restrict ret,
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
}
- if (arraysize > 0)
+ if (likely (arraysize > 0))
ret->data = internal_malloc_size (size * arraysize);
else
ret->data = internal_malloc_size (1);
===================================================================
@@ -90,7 +90,6 @@ eoshift3 (gfc_array_char * const restrict ret,
{
int i;
- ret->data = internal_malloc_size (size * arraysize);
ret->offset = 0;
ret->dtype = array->dtype;
for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
===================================================================
@@ -81,7 +81,6 @@ cshift1 (gfc_array_char * const restrict ret,
{
int i;
- ret->data = internal_malloc_size (size * arraysize);
ret->offset = 0;
ret->dtype = array->dtype;
for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
@@ -98,6 +97,11 @@ cshift1 (gfc_array_char * const restrict ret,
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
}
+ if (likely (arraysize > 0))
+ ret->data = internal_malloc_size (size * arraysize);
+ else
+ ret->data = internal_malloc_size (1);
+
}
else if (unlikely (compile_options.bounds_check))
{
===================================================================
@@ -68,6 +68,8 @@ matmul_'rtype_code` ('rtype` * const restrict reta
if (retarray->data == NULL)
{
+ index_type array_size, alloc_size;
+
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
GFC_DIMENSION_SET(retarray->dim[0], 0,
@@ -87,9 +89,15 @@ matmul_'rtype_code` ('rtype` * const restrict reta
GFC_DESCRIPTOR_EXTENT(b,1) - 1,
GFC_DESCRIPTOR_EXTENT(retarray,0));
}
-
- retarray->data
- = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
+
+ array_size = size0 ((array_t *) retarray);
+
+ if (unlikely (array_size < 1))
+ alloc_size = 1;
+ else
+ alloc_size = sizeof ('rtype_name`) * alloc_size;
+
+ retarray->data = internal_malloc_size ( alloc_size );
retarray->offset = 0;
}
else if (unlikely (compile_options.bounds_check))
===================================================================
@@ -86,6 +86,9 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype`
{
/* The front end has signalled that we need to populate the
return array descriptor. */
+
+ index_type alloc_size;
+
dim = GFC_DESCRIPTOR_RANK (mask);
rs = 1;
for (n = 0; n < dim; n++)
@@ -100,7 +103,13 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype`
rs *= extent[n];
}
ret->offset = 0;
- ret->data = internal_malloc_size (rs * sizeof ('rtype_name`));
+
+ if (unlikely (rs < 1))
+ alloc_size = 1;
+ else
+ alloc_size = rs * sizeof ('rtype_name`);
+
+ ret->data = internal_malloc_size (alloc_size);
}
else
{
===================================================================
@@ -94,6 +94,7 @@ name`'rtype_qual`_'atype_code (rtype * const restr
if (alloc_size == 0)
{
+ retarray->data = internal_malloc_size (1);
/* Make sure we have a zero-sized array. */
GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
return;
===================================================================
@@ -90,6 +90,7 @@ name`'rtype_qual`_'atype_code (rtype * const restr
if (alloc_size == 0)
{
+ retarray->data = internal_malloc_size (1);
/* Make sure we have a zero-sized array. */
GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
return;
@@ -269,6 +270,7 @@ void
if (alloc_size == 0)
{
+ retarray->data = internal_malloc_size (1);
/* Make sure we have a zero-sized array. */
GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
return;
===================================================================
@@ -104,6 +104,8 @@ matmul_'rtype_code` ('rtype` * const restrict reta
if (retarray->data == NULL)
{
+ index_type array_size, alloc_size;
+
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
GFC_DIMENSION_SET(retarray->dim[0], 0,
@@ -124,8 +126,14 @@ matmul_'rtype_code` ('rtype` * const restrict reta
GFC_DESCRIPTOR_EXTENT(retarray,0));
}
+ array_size = size0 ((array_t *) retarray);
+
+ if (unlikely (array_size < 1))
+ alloc_size = 1;
+ else
+ alloc_size = sizeof ('rtype_name`) * array_size;
retarray->data
- = internal_malloc_size (sizeof ('rtype_name`) * size0 ((array_t *) retarray));
+ = internal_malloc_size (alloc_size);
retarray->offset = 0;
}
else if (unlikely (compile_options.bounds_check))
===================================================================
@@ -52,6 +52,8 @@ transpose_internal (gfc_array_char *ret, gfc_array
if (ret->data == NULL)
{
+ index_type alloc_size, array_size;
+
assert (ret->dtype == source->dtype);
GFC_DIMENSION_SET(ret->dim[0], 0, GFC_DESCRIPTOR_EXTENT(source,1) - 1,
@@ -60,7 +62,14 @@ transpose_internal (gfc_array_char *ret, gfc_array
GFC_DIMENSION_SET(ret->dim[1], 0, GFC_DESCRIPTOR_EXTENT(source,0) - 1,
GFC_DESCRIPTOR_EXTENT(source, 1));
- ret->data = internal_malloc_size (size * size0 ((array_t*)ret));
+
+ array_size = size0 ((array_t*)ret);
+ if (unlikely (array_size < 1))
+ alloc_size = 1;
+ else
+ alloc_size = size * array_size;
+
+ ret->data = internal_malloc_size (alloc_size);
ret->offset = 0;
}
else if (unlikely (compile_options.bounds_check))
===================================================================
@@ -111,6 +111,8 @@ unpack_internal (gfc_array_char *ret, const gfc_ar
{
/* The front end has signalled that we need to populate the
return array descriptor. */
+ index_type alloc_size;
+
dim = GFC_DESCRIPTOR_RANK (mask);
rs = 1;
for (n = 0; n < dim; n++)
@@ -126,7 +128,13 @@ unpack_internal (gfc_array_char *ret, const gfc_ar
rs *= extent[n];
}
ret->offset = 0;
- ret->data = internal_malloc_size (rs * size);
+
+ if (unlikely (rs < 1))
+ alloc_size = 1;
+ else
+ alloc_size = rs * size;
+
+ ret->data = internal_malloc_size (alloc_size);
}
else
{