realloc() (was: Re: Safe coding practices)

Rob Carlson rob at jimi.UUCP
Wed Feb 6 09:20:37 AEST 1991


>
>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  



More information about the Comp.lang.c mailing list