This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, fortran] PR28105 Overflow check for memory allocation
On Wed, Dec 15, 2010 at 18:20, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Wed, Dec 15, 2010 at 12:18:16PM +0200, Janne Blomqvist wrote:
>>
>> OTOH since we're calling _gfortran_os_error which calls perror() we
>> get the same message twice just worded slightly differently. E.g.
>>
>> $ ./largealloc
>> Operating system error: Cannot allocate memory
>> Out of memory
>>
>> which is a bit redundant. So maybe just an empty string (or NULL)
>> is sufficient?
>>
>
> In the above, how about changing "Out of memory" to
> "Allocation would exceed system or user memory limit".
> Thus, one would get
>
> $ ./largealloc
> Operating system error: Cannot allocate memory
> Allocation would exceed system or user memory limit
>
> Second, provides a hint to user where to look for
> the problem. ÂWhatever you decide is fine with me.
Sending fortran/ChangeLog
Sending fortran/misc.c
Sending fortran/trans.c
Transmitting file data ...
Committed revision 167863.
Patch below:
diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index 397c872..86e102e 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -36,7 +36,7 @@ gfc_getmem (size_t n)
p = xmalloc (n);
if (p == NULL)
- gfc_fatal_error ("Out of memory-- malloc() failed");
+ gfc_fatal_error ("Allocation would exceed memory limit --
malloc() failed");
memset (p, 0, n);
return p;
}
diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index f3914a1..1fd0dc1 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -590,7 +590,7 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
if (stat)
*stat = LIBERROR_ALLOCATION;
else
- runtime_error ("Out of memory");
+ runtime_error ("Allocation would exceed memory limit");
}
return newmem;
} */
@@ -636,7 +636,7 @@ gfc_allocate_with_status (stmtblock_t * block,
tree size, tree status)
1)))));
msg = gfc_build_addr_expr (pchar_type_node, gfc_build_localized_cstring_const
- ("Out of memory"));
+ ("Allocation would exceed memory limit"));
tmp = build_call_expr_loc (input_location,
gfor_fndecl_os_error, 1, msg);
@@ -1003,7 +1003,7 @@ internal_realloc (void *mem, size_t size)
{
res = realloc (mem, size);
if (!res && size != 0)
- _gfortran_os_error ("Out of memory");
+ _gfortran_os_error ("Allocation would exceed memory limit");
if (size == 0)
return NULL;
@@ -1036,7 +1036,7 @@ gfc_call_realloc (stmtblock_t * block, tree mem,
tree size)
null_result = fold_build2_loc (input_location, TRUTH_AND_EXPR,
boolean_type_node,
null_result, nonzero);
msg = gfc_build_addr_expr (pchar_type_node, gfc_build_localized_cstring_const
- ("Out of memory"));
+ ("Allocation would exceed memory limit"));
tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node,
null_result,
build_call_expr_loc (input_location,
--
Janne Blomqvist