This is the mail archive of the 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

On Fri, 2 Jan 2004, Ian Lance Taylor wrote:

> Although I initially believed otherwise, I now think that it is
> possible to write a reasonable program which may be miscompiled if gcc
> thinks that realloc has the malloc attribute.  Whether such a program
> actually exists in practice, I don't know.  Whether such a program
> strictly conforms to the C standard, I don't know.

Should we really consider such a program more reasonable than the sort of
program accessing freed memory, which certainly exists in practice?  
glibc has had the attribute on realloc for four years (stdlib/stdlib.h
version 1.80), plenty of time for any miscompilation problems with such
code to show up.  (And quite possibly the most likely problems are
harmless pessimisation, if a program e.g. reallocs a datastructure with
internal pointers to itself then fixes up those pointers only when
necessary (or always when the pointers are assumed unequal), though such a
program would definitely be nonconforming when realloc returns a different
pointer (it should use integer indices within the structure rather than
trying to fix up pointers after realloc).)

Joseph S. Myers

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