This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [patch, fortran] Always return malloc(1) for empty arrays in the library
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Thomas Koenig <tkoenig at netcologne dot de>
- Cc: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 29 Jun 2011 10:04:55 +0300
- Subject: Re: [patch, fortran] Always return malloc(1) for empty arrays in the library
- References: <4E0A4C94.7030602@netcologne.de>
On Wed, Jun 29, 2011 at 00:50, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hello world,
>
> looking at PR 49479 and other functions in the library made me realize
> there are lots of places where we don't malloc one byte for empty
> arrays.
I'd prefer to add the zero check to runtime/memory.c
(internal_malloc_size), i.e. change
if (size == 0)
return NULL;
to
if (size == 0)
size = 1;
Or perhaps even better would be to add that check to get_mem() instead
(as a side effect making internal_malloc_size redundant), thus
matching how memory allocation works in the frontend? Looking at
get_mem() we actually have a small bug here; if size == 0 and malloc
happens to return NULL we treat it as an error.
--
Janne Blomqvist