Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 21 Jul 2020 17:19:26 -0600
From: Ariadne Conill <ariadne@...eferenced.org>
To: musl@...ts.openwall.com
Subject: Re: perhaps we should add re[c]allocarray?

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


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.