This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
malloc attributes and realloc
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 1 Jan 2004 11:24:32 +0000 (UTC)
- Subject: malloc attributes and realloc
Can __attribute__((__malloc__)) safely be used on realloc-type functions?
glibc's <stdlib.h> has
extern void *realloc (void *__ptr, size_t __size) __THROW __attribute_malloc__;
while libiberty.h has
/* Reallocate memory without fail. This works like xmalloc. Note,
realloc type functions are not suitable for attribute malloc since
they may return the same address across multiple calls. */
extern PTR xrealloc PARAMS ((PTR, size_t));
- which is correct? (Although the same value can be returned by realloc,
the program can't compare the values as values without undefined behavior,
only as bit patterns - and using them as bit patterns (a) involves taking
the address of one of the pointers involved (possibly inhibiting
optimization that way), (b) gets into the territory of DR#260.)
--
Joseph S. Myers
jsm@polyomino.org.uk