This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: Jeff Sturm <jsturm at one-point dot com>
- Cc: "Joseph S. Myers" <jsm at polyomino dot org dot uk>, gcc at gcc dot gnu dot org
- Date: 01 Jan 2004 10:38:04 -0500
- Subject: Re: malloc attributes and realloc
- References: <Pine.LNX.4.44.0401011012480.14653-100000@ops2.one-point.com>
Jeff Sturm <jsturm@one-point.com> writes:
> What *is* significant is
> that malloc returns memory initialized with zeros, so that it cannot
> alias anything.
That's not true, though. malloc() returns an uninitialized block of
memory.
The return value of malloc() can not alias any valid pointer.
If realloc() returns non-NULL, then the return value can not alias any
valid pointer, because it is no longer valid to use the pointer which
was passed to it (if realloc() returns NULL, on the other hand, then
it is still valid to use the pointer which was passed to it). So I
think it is OK to give realloc() __attribute__((malloc)).
Ian