diff options
Diffstat (limited to 'libgfortran/m4/reshape.m4')
-rw-r--r-- | libgfortran/m4/reshape.m4 | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4 index 4052a5e..d1486f3 100644 --- a/libgfortran/m4/reshape.m4 +++ b/libgfortran/m4/reshape.m4 @@ -101,6 +101,8 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret, if (ret->data == NULL) { + index_type alloc_size; + rs = 1; for (n = 0; n < rdim; n++) { @@ -111,7 +113,13 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret, rs *= rex; } 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); ret->dtype = (source->dtype & ~GFC_DTYPE_RANK_MASK) | rdim; } |