From: Rich Felker <dalias@libc.org>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: "Rüdiger Sonderfeld" <ruediger@c-plusplus.de>,
"Paul Eggert" <eggert@cs.ucla.edu>,
libc-alpha@sourceware.org
Subject: Re: [RFC][PATCH v2] Add reallocarray function.
Date: Tue, 20 May 2014 04:35:00 -0000 [thread overview]
Message-ID: <20140520020108.GV507@brightrain.aerifal.cx> (raw)
In-Reply-To: <Pine.LNX.4.64.1405191501120.25418@digraph.polyomino.org.uk>
On Mon, May 19, 2014 at 03:02:52PM +0000, Joseph S. Myers wrote:
> On Sun, 18 May 2014, R?diger Sonderfeld wrote:
>
> > diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
> > index 00329a2..b75c28f 100644
> > --- a/stdlib/stdlib.h
> > +++ b/stdlib/stdlib.h
> > @@ -479,6 +479,13 @@ extern void *calloc (size_t __nmemb, size_t __size)
> > between objects pointed by the old and new pointers. */
> > extern void *realloc (void *__ptr, size_t __size)
> > __THROW __attribute_warn_unused_result__;
> > +/* Re-allocate the previously allocated block in PTR, making the new
> > + block large enough for NMEMB elements of SIZE bytes each. */
> > +/* __attribute_malloc__ is not used, because if realloc returns
> > + the same pointer that was passed to it, aliasing needs to be allowed
> > + between objects pointed by the old and new pointers. */
> > +extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
> > + __THROW __attribute_warn_unused_result__;
>
> How has this patch been tested? This function declaration needs
> conditioning on __USE_GNU, as no standard includes this function in
> <stdlib.h>; I'd have expected you to get failures of the conform/ tests
> for stdlib.h when you ran the testsuite.
Not really related to this patch, but I think the comment about
__attribute_malloc__ that was copied from realloc is wrong. The new
and old pointers cannot alias because, if realloc succeeds (and I
would expect reallocarray to behave the same) the _value_ of the old
pointer is indeterminate and accessing it (e.g. comparing it with new)
invokes undefined behavior.
Rich
next prev parent reply other threads:[~2014-05-20 2:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-18 21:05 [RFC][PATCH] " Rüdiger Sonderfeld
2014-05-18 21:43 ` Paul Eggert
2014-05-18 21:50 ` [RFC][PATCH v2] " Rüdiger Sonderfeld
2014-05-19 4:27 ` Rüdiger Sonderfeld
2014-05-19 15:30 ` Joseph S. Myers
2014-05-20 4:35 ` Rich Felker [this message]
2014-05-20 8:17 ` Paul Eggert
2014-05-20 8:19 ` Andreas Schwab
2014-05-20 15:45 ` Paul Eggert
2014-05-20 20:47 ` Rich Felker
2014-05-20 20:56 ` Paul Eggert
2014-05-20 12:50 ` Rüdiger Sonderfeld
2014-05-20 14:18 ` Paul Eggert
2014-05-21 12:39 ` Rüdiger Sonderfeld
2014-05-22 5:45 ` Paul Eggert
2014-09-01 15:48 ` [RFC][PATCH] " Florian Weimer
2014-09-01 17:24 ` Rich Felker
2014-09-02 9:29 ` Florian Weimer
2014-09-02 13:03 ` Rich Felker
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=20140520020108.GV507@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=eggert@cs.ucla.edu \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
--cc=ruediger@c-plusplus.de \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).