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

Kaleb Keithley kaleb at thyme.jpl.nasa.gov
Thu Jan 31 07:42:10 AEST 1991


In article <1991Jan30.193308.3897 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>In article <1991Jan30.121425.16882 at unhd.unh.edu>, pas at unhd.unh.edu (Paul A. Sand) writes:
>|> 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
>|> access to the block, and (c) you had something important there.
>
>  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().

the man page (on Sun) states the following:     
     ... If unable to honor a reallocation request, realloc() leaves 
     its first argument unaltered....

K&RII states the following:
    ... realloc returns [...] NULL if the request cannot be satisfied, in which
    case [the first argument] is unchanged.

-- 
Kaleb Keithley                        kaleb at thyme.jpl.nasa.gov

As of right now, I'm in charge here now...                  Alexander Haig.
Voodoo Economics, that's what it is, voodoo economics.      George Bush



More information about the Comp.lang.c mailing list