This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]