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 10458 invoked from network); 11 May 2021 13:04:08 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 11 May 2021 13:04:08 -0000 Received: (qmail 18151 invoked by uid 550); 11 May 2021 13:04:06 -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 18130 invoked from network); 11 May 2021 13:04:05 -0000 Date: Tue, 11 May 2021 09:03:53 -0400 From: Rich Felker To: David CARLIER , g@port70.net, musl@lists.openwall.com Message-ID: <20210511130352.GI2546@brightrain.aerifal.cx> References: <20210511073306.GQ2799122@port70.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511073306.GQ2799122@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH 1/1] reallocarray casting overflow check explicitally On Tue, May 11, 2021 at 09:33:06AM +0200, Szabolcs Nagy wrote: > * David CARLIER [2021-05-10 20:48:26 +0100]: > > From 04e3caa580cfe501ad00d85d63040de329962823 Mon Sep 17 00:00:00 2001 > > From: David Carlier > > Date: Mon, 10 May 2021 20:45:12 +0100 > > Subject: [PATCH] reallocarray overflow check cast to size_t > > > > --- > > src/malloc/reallocarray.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c > > index 4a6ebe46..2556c917 100644 > > --- a/src/malloc/reallocarray.c > > +++ b/src/malloc/reallocarray.c > > @@ -4,7 +4,7 @@ > > > > void *reallocarray(void *ptr, size_t m, size_t n) > > { > > - if (n && m > -1 / n) { > > + if (n && m > (size_t)-1 / n) { > > you need to explain this change more i think. > > the usual arithmetic conversion rules of c already convert both > operands of / to size_t, unless size_t has lower conversion rank > than signed int, but such a system would have problems because > size_t was always promoted to int so you would need a lot more > casts in musl (and other software) to avoid signed int overflow > and negative arithmetics. I think the idea was just to make it explicit, but generally casting is discouraged in musl. The corresponding code in calloc has a cast but it's a historical artifact and contrary to the coding style used throughout most of the source. Rich