🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #270

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

#270
From: Paul A. Sand
Date: Wed, 30 Jan 1991 12:14
27 lines
1790 bytes
In article <23975:Jan2516:36:5891@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
>Some versions of realloc() return the original pointer rather than 0 if
>they run out of memory. So you have to code the malloc()/bcopy()/free()
>sequence yourself if you want error checking.

Other posters have pointed out that such realloc()'s are seriously
broken, but I wonder how many versions "some versions" actually are.  A
brief check of my portability references (Jaeschke's _Portability and
the C Language_, Rabinowitz's and Schaap's _Portable C_, 1st and 3rd
editions of Harbison & Steele) doesn't turn up any warnings about such
behavior. (And these folks seem to warn about *very* unlikely things.)

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
access to the block, and (c) you had something important there.
-- 
-- Paul A. Sand                |
-- University of New Hampshire | I ain't here on business, baby.
-- uunet!unhd!pas              | I'm only here for fun.
-- pas@unhd.unh.edu            |
Technical Details
Message-ID: <1991Jan30.121425.16882@unhd.unh.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!unhd.unh.edu!pas
References: <23975:Jan2516:36:5891@kramden.acf.nyu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!unhd.unh.edu!pas
From: pas@unhd.unh.edu (Paul A. Sand)
Newsgroups: comp.bugs.4bsd,comp.std.c,comp.lang.c
Subject: realloc() (was: Re: Safe coding practices)
Message-ID: <1991Jan30.121425.16882@unhd.unh.edu>
Date: 30 Jan 91 12:14:25 GMT
References: <23975:Jan2516:36:5891@kramden.acf.nyu.edu>
Reply-To: pas@unhd.unh.edu (Paul A. Sand)
Followup-To: comp.lang.c
Organization: University of New Hampshire
Lines: 27