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.3 required=5.0 tests=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 6144 invoked from network); 21 Jul 2020 19:40:59 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 21 Jul 2020 19:40:59 -0000 Received: (qmail 10170 invoked by uid 550); 21 Jul 2020 19:40:55 -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 10145 invoked from network); 21 Jul 2020 19:40:55 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=mTPDs06U5iWxKx8aryuQ6TcwAgei0jEHECMSl5DFQ94=; b=ChcTMGYW4ZYElrklOy3ZRZPMPFyqTMSSw14sTQTLcw7jiYjce32HK8j4wkIaeV++bp eQXtfVjGkQxluibBDrmiDqaFSo+QfSU6l7+EIEQMP217MP8nadM07gOFLV5pGLtXGlWw fKs5Pa8GGBpKHVMH2wf1o/2m3siBieaJKyKJ0fqgeTF2R90FxmTH9W3KuIvoLRo4Taz/ A5cudwDAB7ICY3CrRwGvcHJs9oRlbS3Ma9eoXpt0knyj42goM54AB20NCfJiUkD375wL 1hjZrVkOSPXyxpxrSht7rXVJEH+bBJI8EXSFansuA5pkeQvHGTJS0tV3MDKuGI6dEe2q Fbgw== X-Gm-Message-State: AOAM532IuyyH//s1d4ryBS58OTOWcXhl8ucTEYHqWdFFoCAeAFP2yTub 9qpFMALt+1JMseHEkAM6KLE= X-Google-Smtp-Source: ABdhPJzYJmsEpfWRzbTN4sA2Wq6Ct3b7OY8SiMgqyeYlti6FBOP2br1Kkz2gqna8tAZRCTG5VKcewg== X-Received: by 2002:adf:fd8b:: with SMTP id d11mr807830wrr.156.1595360443502; Tue, 21 Jul 2020 12:40:43 -0700 (PDT) From: Leah Neukirchen To: Rich Felker Cc: Ariadne Conill , musl@lists.openwall.com References: <3289935.7VNl89jVkd@localhost> <20200721183945.GQ14669@brightrain.aerifal.cx> Date: Tue, 21 Jul 2020 21:40:41 +0200 In-Reply-To: <20200721183945.GQ14669@brightrain.aerifal.cx> (Rich Felker's message of "Tue, 21 Jul 2020 14:39:46 -0400") Message-ID: <87lfjcac7a.fsf@vuxu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [musl] perhaps we should add re[c]allocarray? Rich Felker writes: > 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. > > reallocarray is a straightforward wrapper around realloc that can be > implemented portably to work with arbitrary underlying malloc and is > fairly non-controversial. I think it was already loosely agreed at > some point that we would eventually support this. > > recallocarray presumably needs to zero the new part which means it > needs to know the old exact size, which means it depends on having > either knowledge of implementation internals or a working, exact > malloc_usable_size (AFAIK all legacy/existing ones except musl > mallocng are broken and return a value greater than the originally > allocated size). Implementing it interferes with safety of > overriding/interposing malloc, and therefore I'm fairly strongly > against it unless there's a widepread consensus between implementors > that it should exist. No, it's an argument: void *recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) -- Leah Neukirchen https://leahneukirchen.org/