summaryrefslogtreecommitdiff
path: root/libgfortran/generated/count_8_l4.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/generated/count_8_l4.c')
-rw-r--r--libgfortran/generated/count_8_l4.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/libgfortran/generated/count_8_l4.c b/libgfortran/generated/count_8_l4.c
index 1a5451bf3e2..9ecddbd10b1 100644
--- a/libgfortran/generated/count_8_l4.c
+++ b/libgfortran/generated/count_8_l4.c
@@ -69,16 +69,24 @@ count_8_l4 (gfc_array_i8 * const restrict retarray,
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
+
+ if (extent[n] < 0)
+ extent[n] = 0;
}
if (retarray->data == NULL)
{
+ size_t alloc_size;
+
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
@@ -89,12 +97,21 @@ count_8_l4 (gfc_array_i8 * const restrict retarray,
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
- retarray->data
- = internal_malloc_size (sizeof (GFC_INTEGER_8)
- * retarray->dim[rank-1].stride
- * extent[rank-1]);
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
+
+ alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
+ * extent[rank-1];
+
+ if (alloc_size == 0)
+ {
+ /* Make sure we have a zero-sized array. */
+ retarray->dim[0].lbound = 0;
+ retarray->dim[0].ubound = -1;
+ return;
+ }
+ else
+ retarray->data = internal_malloc_size (alloc_size);
}
else
{