Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!uplherc!wicat!jimi!rob From: rob@jimi.UUCP (Rob Carlson) Newsgroups: comp.lang.c Subject: Re: realloc() (was: Re: Safe coding practices) Message-ID: <00066@jimi.UUCP> Date: 5 Feb 91 22:20:37 GMT References: <23975:Jan2516:36:5891@kramden.acf.nyu.edu> <1991Jan30.121425.16882@unhd.unh.edu> Reply-To: rob@jimi.UUCP Organization: WICAT Systems Inc., Orem Utah Lines: 24 > >But as long as I'm reading, I did notice a howler in Jaeschke's text, >on page 320: > > You should ALWAYS use realloc as follows: > > ptr = realloc(ptr, new_size); > >Emphasis is Jaeschke's. Even a tyro like me can recognize that you >are in big trouble if (a) the realloc() fails, (b) ptr is your only My understanding has always been that if realloc() fails (returns NULL), ALL access to the previously allocated block is gone. It makes no difference whether you keep the original ptr or not. This has stuck in my head because of a particularly nasty bug due to assuming that the original ptr was still valid after the failure. But I can't seem to find an adequate reference to back up my 'understanding'. Can anyone cite ANSI or any other reference to clear this up? Rob Carlson