From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7795 invoked from network); 22 Jul 2020 00:18:34 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 22 Jul 2020 00:18:34 -0000 Received: (qmail 14186 invoked by uid 550); 22 Jul 2020 00:18:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 28441 invoked from network); 21 Jul 2020 23:19:42 -0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dereferenced.org; s=default; t=1595373570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4kai2AQruGgiY7uzZ3fITT88Zf6dVX0egMwYCwqVNfM=; b=XayU7w36Nq+rpUGB/tJ3gXE+Jhjyxc47kItNAWg8Iv98NuhS795QY9qZitgRzWa6/k6IJ3 JepbEZbDloNkJoUTAaABYjCJmjaWDqAT3t96M+lllC8OXywqzog2RTUF+v929svi6hKN0K ja+lk0eFoq8/+Z5l17UfqjMJucGxQso= From: Ariadne Conill To: musl@lists.openwall.com Date: Tue, 21 Jul 2020 17:19:26 -0600 Message-ID: <3409019.y9zrWrDLY7@localhost> In-Reply-To: <20200721165657.GA2160@voyager> References: <3289935.7VNl89jVkd@localhost> <20200721165657.GA2160@voyager> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [musl] 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