Index: m4/in_pack.m4 =================================================================== --- m4/in_pack.m4 (Revision 175598) +++ m4/in_pack.m4 (Arbeitskopie) @@ -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]; Index: m4/transpose.m4 =================================================================== --- m4/transpose.m4 (Revision 175598) +++ m4/transpose.m4 (Arbeitskopie) @@ -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)) { Index: m4/eoshift1.m4 =================================================================== --- m4/eoshift1.m4 (Revision 175598) +++ m4/eoshift1.m4 (Arbeitskopie) @@ -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); Index: m4/eoshift3.m4 =================================================================== --- m4/eoshift3.m4 (Revision 175598) +++ m4/eoshift3.m4 (Arbeitskopie) @@ -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++) Index: m4/cshift1.m4 =================================================================== --- m4/cshift1.m4 (Revision 175598) +++ m4/cshift1.m4 (Arbeitskopie) @@ -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)) { Index: m4/matmull.m4 =================================================================== --- m4/matmull.m4 (Revision 175598) +++ m4/matmull.m4 (Arbeitskopie) @@ -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)) Index: m4/unpack.m4 =================================================================== --- m4/unpack.m4 (Revision 175598) +++ m4/unpack.m4 (Arbeitskopie) @@ -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 { Index: m4/ifunction_logical.m4 =================================================================== --- m4/ifunction_logical.m4 (Revision 175598) +++ m4/ifunction_logical.m4 (Arbeitskopie) @@ -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; Index: m4/ifunction.m4 =================================================================== --- m4/ifunction.m4 (Revision 175598) +++ m4/ifunction.m4 (Arbeitskopie) @@ -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; Index: m4/matmul.m4 =================================================================== --- m4/matmul.m4 (Revision 175598) +++ m4/matmul.m4 (Arbeitskopie) @@ -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)) Index: intrinsics/transpose_generic.c =================================================================== --- intrinsics/transpose_generic.c (Revision 175598) +++ intrinsics/transpose_generic.c (Arbeitskopie) @@ -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)) Index: intrinsics/unpack_generic.c =================================================================== --- intrinsics/unpack_generic.c (Revision 175598) +++ intrinsics/unpack_generic.c (Arbeitskopie) @@ -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 {