From: Ariadne Conill <ariadne@dereferenced.org>
To: musl@lists.openwall.com
Subject: Re: [musl] perhaps we should add re[c]allocarray?
Date: Tue, 21 Jul 2020 17:19:26 -0600 [thread overview]
Message-ID: <3409019.y9zrWrDLY7@localhost> (raw)
In-Reply-To: <20200721165657.GA2160@voyager>
Hello,
On Tuesday, July 21, 2020 10:56:57 AM MDT Markus Wichmann wrote:
> On Tue, Jul 21, 2020 at 04:18:35AM -0600, Ariadne Conill wrote:
> > Hello,
> >
> > reallocarray and recallocarray are BSD extensions that solve similar
> > issues as strlcpy/strlcat, but with array reallocations instead of
> > strings.
> >
> > reallocarray itself is already part of glibc since 2.28.
> >
> > Unfortunately, while working on new ifupdown implementation for Alpine, I
> > wanted to use recallocarray because it is very helpful in terms of pushing
> > new strings to a string array (you will always maintain a NULL-terminated
> > array, and you don't have to worry about it) -- but I discovered musl
> > still does not have it.
> >
> > Anyway, I think it would be useful to include both functions in musl
> > 1.2.1.
> > If everyone agrees, I'll make a patch.
> >
> > Ariadne
>
> Seems mostly useless to me. reallocarray() is equivalent to realloc(),
> multiplying the last two arguments. And recallocarray() does seem
> useful, but moreso as a subroutine. I see little reason to put this into
> a standard library.
The reason is that we would like to see people use these routines instead of
fussing with realloc() directly because they do the right thing. It is better
to provide the right thing in the standard library instead of having people
mess it up with their own implementation.
> On a formal point of view, neither of these has been standardized. I can
> find an Oracle man page for reallocarray(), but not recallocarray().
> Both are OpenBSD extensions. For glibc, I can find reallocarray() (which
> mostly wraps realloc()), but no recallocarray() (I checked in the most
> recent released version, which is 2.31 as of right now).
As I previously stated, both are BSD extensions, so I do not understand why
you are mentioning it again. At any rate, I plan to propose these extensions
for inclusion in next POSIX revision. Just haven't gotten around to writing
to the Austin Group yet.
> It appears, reallocarray() enjoys more widespread adoption than
> recallocarray(). Both can, however, be easily found by a compile/link
> test. As stated above, however, the necessary functionality can easily
> be written in whatever application needs it, so I don't see the point.
> I've done that before; it is two lines if you manage your variables
> well.
While it is possible to probe for these functions using autoconf or meson or
whatever, Alpine approaches these concerns from the standpoint that the libc
provides what Alpine requires for its own utilities. For now, we will carry
our own recallocarray in ifupdown, but it would be nice to drop this at some
point. That is what *this* thread is about.
Ariadne
next prev parent reply other threads:[~2020-07-22 0:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-21 10:18 Ariadne Conill
2020-07-21 16:56 ` Markus Wichmann
2020-07-21 17:27 ` Hadrien Lacour
2020-07-21 23:19 ` Ariadne Conill [this message]
2020-07-21 18:39 ` Rich Felker
2020-07-21 18:58 ` Florian Weimer
2020-07-21 20:40 ` Rich Felker
2020-07-21 23:21 ` Ariadne Conill
2020-07-22 0:21 ` Rich Felker
2020-07-22 0:24 ` Ariadne Conill
2020-07-21 19:40 ` Leah Neukirchen
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=3409019.y9zrWrDLY7@localhost \
--to=ariadne@dereferenced.org \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).