Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown) Newsgroups: comp.lang.c Subject: Re: realloc() (was: Re: Safe coding practices) Message-ID: <3048.27a9786d@iccgcc.decnet.ab.com> Date: 1 Feb 91 19:17:17 GMT References: <23975:Jan2516:36:5891@kramden.acf.nyu.edu> <1991Jan30.121425.16882@unhd.unh.edu> <1991Jan30.193308.3897@athena.mit.edu> Lines: 17 In article <1991Jan30.193308.3897@athena.mit.edu>, jik@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@ab.com -or- browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, USA +1 216 371 0043