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

Stan Brown browns at iccgcc.decnet.ab.com
Sat Feb 2 06:17:17 AEST 1991


In article <1991Jan30.193308.3897 at athena.mit.edu>, 
jik at athena.mit.edu (Jonathan I. Kamens) writes:
>   I believe that if the realloc() fails, the memory block pointed to by the
> pointer passed into realloc() is no longer guaranteed to be valid.  Therefore,
> Jaeschke is right -- after realloc() returns NULL, you should not try to use
> the block whose address you passed into realloc().

ANSI X3.159-1989, pg 156, lines 23-24 (sec 4.10.3.4, The realloc
Function): "If the space cannot be allocated, the object pointed to by
ptr is unchanged."  'ptr' is the first argument to the function.

So in case of failure of new allocation, the old block _is_ guaranteed
to be untouched--unless the library is broken.

Hey--this is all my opinion, nobody else's. Rely on it at your peril.
                email: browns at ab.com -or- browns at iccgcc.decnet.ab.com
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA    +1 216 371 0043



More information about the Comp.lang.c mailing list