===================================================================
@@ -54,8 +54,8 @@ get_mem (size_t n)
void *
internal_malloc_size (size_t size)
{
- if (size == 0)
- return NULL;
+ if (unlikely (size <= 0))
+ size = 1;
return get_mem (size);
}
===================================================================
@@ -167,14 +167,12 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *ar
GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1);
ret->offset = 0;
+
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (sizeof ('rtype_name`) * total);
+
if (total == 0)
- {
- /* In this case, nothing remains to be done. */
- ret->data = internal_malloc_size (1);
- return;
- }
- else
- ret->data = internal_malloc_size (sizeof ('rtype_name`) * total);
+ return;
}
else
{
===================================================================
@@ -101,13 +101,11 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *
GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
}
ret->offset = 0;
- if (rs > 0)
- ret->data = internal_malloc_size (rs * sizeof('rtype_name`));
- else
- {
- ret->data = internal_malloc_size (1);
- return;
- }
+
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (rs * sizeof('rtype_name`));
+ if (rs <= 0)
+ return;
}
else
{
===================================================================
@@ -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,10 +106,8 @@ eoshift1 (gfc_array_char * const restrict ret,
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
}
- if (arraysize > 0)
- ret->data = internal_malloc_size (size * arraysize);
- else
- ret->data = internal_malloc_size (1);
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * arraysize);
}
else if (unlikely (compile_options.bounds_check))
===================================================================
@@ -108,10 +108,8 @@ eoshift3 (gfc_array_char * const restrict ret,
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
}
- if (arraysize > 0)
- ret->data = internal_malloc_size (size * arraysize);
- else
- ret->data = internal_malloc_size (1);
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * arraysize);
}
else if (unlikely (compile_options.bounds_check))
===================================================================
@@ -153,14 +153,11 @@ pack_internal (gfc_array_char *ret, const gfc_arra
GFC_DIMENSION_SET(ret->dim[0], 0, total-1, 1);
ret->offset = 0;
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * total);
+
if (total == 0)
- {
- /* In this case, nothing remains to be done. */
- ret->data = internal_malloc_size (1);
- return;
- }
- else
- ret->data = internal_malloc_size (size * total);
+ return; /* In this case, nothing remains to be done. */
}
else
{
@@ -523,13 +520,10 @@ pack_s_internal (gfc_array_char *ret, const gfc_ar
ret->offset = 0;
+ ret->data = internal_malloc_size (size * total);
+
if (total == 0)
- {
- ret->data = internal_malloc_size (1);
- return;
- }
- else
- ret->data = internal_malloc_size (size * total);
+ return;
}
rstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(ret,0);
===================================================================
@@ -79,10 +79,8 @@ cshift0 (gfc_array_char * ret, const gfc_array_cha
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
}
- if (arraysize > 0)
- ret->data = internal_malloc_size (size * arraysize);
- else
- ret->data = internal_malloc_size (1);
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * arraysize);
}
else if (unlikely (compile_options.bounds_check))
{
===================================================================
@@ -100,13 +100,10 @@ spread_internal (gfc_array_char *ret, const gfc_ar
GFC_DIMENSION_SET(ret->dim[n], 0, ub, stride);
}
ret->offset = 0;
- if (rs > 0)
- ret->data = internal_malloc_size (rs * size);
- else
- {
- ret->data = internal_malloc_size (1);
- return;
- }
+ ret->data = internal_malloc_size (rs * size);
+
+ if (rs <= 0)
+ return;
}
else
{
===================================================================
@@ -86,11 +86,8 @@ eoshift0 (gfc_array_char * ret, const gfc_array_ch
}
- if (arraysize > 0)
- ret->data = internal_malloc_size (size * arraysize);
- else
- ret->data = internal_malloc_size (1);
-
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * arraysize);
}
else if (unlikely (compile_options.bounds_check))
{
===================================================================
@@ -91,10 +91,8 @@ eoshift2 (gfc_array_char *ret, const gfc_array_cha
GFC_DIMENSION_SET(ret->dim[i], 0, ub, str);
- if (arraysize > 0)
- ret->data = internal_malloc_size (size * arraysize);
- else
- ret->data = internal_malloc_size (1);
+ /* internal_malloc_size allocates a single byte for zero size. */
+ ret->data = internal_malloc_size (size * arraysize);
}
}