The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: jgevaryahu@hotmail.com (Jonathan Gevaryahu)
Subject: [TUHS] Did realloc ever zero the new memory?
Date: Thu, 17 Sep 2015 00:42:17 -0400	[thread overview]
Message-ID: <BLU436-SMTP10A7EC9CEEA31EF2963B7CC75A0@phx.gbl> (raw)
In-Reply-To: <20150914032045.GM3796@eureka.lemis.com>

On 9/13/2015 11:20 PM, Greg 'groggy' Lehey wrote:
> On Sunday, 13 September 2015 at 16:09:55 +1000, Dave Horsfall wrote:
>> On Sat, 12 Sep 2015, Larry McVoy wrote:
>>
>>> That's a really good point.  Anyone like these?
>>>
>>> void *alloc(size_t bytes);
>>> void *realloc(void *old, size_t want);
>>>
>>> void *zalloc(size_t bytes);
>>> void *zealloc(void *old, size_t want);
>>>
>>> So alloc is new, we can have that.  Realloc() is OK?  Or not?  Does the
>>> current one have weird semantics?
>>>
>>> zalloc/zealloc are new, we can have those.
>>>
>>> If you guys like these I can push on Linus and the glibc people.
>> I'll vote for those, although my dev days are pretty much over.  I've
>> never liked malloc() etc not clearing memory, although it has been, ahem,
>> useful, in the past...
> http://xkcd.com/927/
>
> Greg
Why not crealloc? pronounced 'cereal-oc'? it would behave the same as 
realloc, but explicitly zeroes the area upon allocating it (and maybe 
also upon reducing the size of the area, it zeroes the area freed, or 
zeroes the area the memory structure was previously located at, if the 
whole memory structure has to be moved.)

Borrowing from 
http://pubs.opengroup.org/onlinepubs/009695399/functions/realloc.html :

The /crealloc/() function shall change the size of the memory object 
pointed to by /ptr/ to the size specified by /size/. The contents of the 
object shall remain unchanged up to the lesser of the new and old sizes. 
If the new size of the memory object would require movement of the 
object, the space for the previous instantiation of the object is 
zeroed, then freed. If the new size is larger, the contents of the newly 
allocated portion of the object are explicitly set to the value of 0. If 
/size/ is 0 and /ptr/ is not a null pointer, the object pointed to is 
zeroed, then freed. If the space cannot be allocated, the object shall 
remain unchanged.

If /ptr/ is a null pointer, /crealloc/() shall be equivalent to 
/calloc/() 
<http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html> 
for the specified size.

If /ptr/ does not match a pointer returned earlier by /calloc/() 
<http://pubs.opengroup.org/onlinepubs/009695399/functions/calloc.html>, 
/malloc/() 
<http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html>, 
/realloc/() or /crealloc/() or if the space has previously been 
deallocated by a call to /free/() 
<http://pubs.opengroup.org/onlinepubs/009695399/functions/free.html>, 
/realloc/() or /crealloc/(), the behavior is undefined.

The order and contiguity of storage allocated by successive calls to 
/crealloc/() is unspecified. The pointer returned if the allocation 
succeeds shall be suitably aligned so that it may be assigned to a 
pointer to any type of object and then used to access such an object in 
the space allocated (until the space is explicitly freed or 
reallocated). Each such allocation shall yield a pointer to an object 
disjoint from any other object. The pointer returned shall point to the 
start (lowest byte address) of the allocated space. If the space cannot 
be allocated, a null pointer shall be returned.


-- 
Jonathan Gevaryahu AKA Lord Nightmare
jgevaryahu at gmail.com
jgevaryahu at hotmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20150917/3ae728f5/attachment.html>


  reply	other threads:[~2015-09-17  4:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13  0:32 Doug McIlroy
2015-09-13  1:15 ` Larry McVoy
2015-09-13  6:09   ` Dave Horsfall
2015-09-14  3:20     ` Greg 'groggy' Lehey
2015-09-17  4:42       ` Jonathan Gevaryahu [this message]
2015-09-13  7:06   ` markus schnalke
2015-09-13 10:32     ` Dave Horsfall
2015-09-13 11:06       ` markus schnalke
2015-09-13 12:13     ` Derek Fawcus
2015-09-13 13:45       ` John Cowan
2015-09-13  1:30 ` Random832
2015-09-13  2:29   ` Charles Anthony
     [not found] <1441931343.25526.for-standards-violators@oclsc.org>
2015-09-12  5:16 ` Dave Horsfall
2015-09-12  6:47   ` Greg 'groggy' Lehey
  -- strict thread matches above, loose matches on Subject: below --
2015-09-11 15:41 Norman Wilson
2015-09-11 16:44 ` scj
2015-09-10 19:52 David
2015-09-10 20:10 ` Jim Capp
2015-09-10 20:21   ` Larry McVoy
2015-09-10 20:22     ` David
2015-09-10 20:27       ` Larry McVoy
2015-09-10 20:29         ` David
2015-09-10 20:41     ` Clem Cole
2015-09-11  6:30       ` arnold
2015-09-11 14:36         ` Clem Cole
2015-09-11  0:13 ` Dave Horsfall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BLU436-SMTP10A7EC9CEEA31EF2963B7CC75A0@phx.gbl \
    --to=jgevaryahu@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).