[Patch, fortran] PR28105 Overflow check for memory allocation

Janne Blomqvist blomqvist.janne@gmail.com
Wed Dec 15 10:18:00 GMT 2010


On Tue, Dec 14, 2010 at 08:41, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Mon, Dec 13, 2010 at 11:06:08PM +0200, Janne Blomqvist wrote:
>> Hi,
>>
>> as a result of a recent commit, size_t in the gfortran frontend is now
>> properly an unsigned type. As a side-effect of this, testing whether a
>> value of type size_t is negative just generates dead code which is
>> optimized away. This kind of test was previously used as a crude kind
>> of overflow check for memory allocation (for the ALLOCATE statement
>> there is now a proper implementation).
>>
>> The attached patch removes the generation of this dead code in the first place.
>>
>> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?
>>
>
> OK.

Thanks.

> Just out of curiousity, your error message is now "Out of memory".
> If someone's shell restricts that amount of memory allowed to be
> allocate, one could run into an allocation issue even though the
> system has memory available.  Won't a better error message be
> "memory allocation issue"?

Good point. POSIX specifies that if malloc() returns NULL, errno is
set to ENOMEM which, according to the spec, means "Insufficient
storage space is available."

http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html

This might mean that, yes, the system is out of memory, or it might
mean something else like a per-process or per-user limit preventing
the allocation from succeeding, as you say. Any ideas for a suitable
wording? IMHO the POSIX "Insufficient storage space is available."
error message might confuse a user to believe e.g. that (s)he is out
of disk space or something like that, so I'd suggest "Memory
allocation error" or "Error allocating memory". "Issue" is maybe a bit
vague (did it actually succeed or not?)?

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?


-- 
Janne Blomqvist



More information about the Fortran mailing list