From: Paul Eggert Date: Tue, 7 Nov 2023 18:54:58 +0000 (-0800) Subject: malloca: pacify -Wcheri-provenance X-Git-Tag: v1.0~624 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ceda36436fe966377eba3d48acc26ebd00154549;p=gnulib.git malloca: pacify -Wcheri-provenance This shouldn’t affect generated code when optimizing. * lib/malloca.c (mmalloca): Pacify -Wcheri-provenance on CHERI-64 cc. (freea): Assign to temporaries to simplify debugging and avoid casts. --- diff --git a/ChangeLog b/ChangeLog index c206ebccc9..b93b28f326 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-11-07 Paul Eggert + + malloca: pacify -Wcheri-provenance + This shouldn’t affect generated code when optimizing. + * lib/malloca.c (mmalloca): Pacify -Wcheri-provenance on CHERI-64 cc. + (freea): Assign to temporaries to simplify debugging and avoid casts. + 2023-11-07 Bruno Haible rawmemchr: Port to CHERI. diff --git a/lib/malloca.c b/lib/malloca.c index f055b1e5ca..690ce2324b 100644 --- a/lib/malloca.c +++ b/lib/malloca.c @@ -60,7 +60,7 @@ mmalloca (size_t n) /* The ckd_add avoids signed integer overflow on theoretical platforms where UINTPTR_MAX <= INT_MAX. */ ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1); - idx_t offset = ((umemplus & ~alignment2_mask) + idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max) + sa_alignment_max - umem); void *vp = mem + offset; small_t *p = vp; @@ -90,15 +90,18 @@ void freea (void *p) { /* Check argument. */ - if ((uintptr_t) p & (sa_alignment_max - 1)) + uintptr_t u = (uintptr_t) p; + if (u & (sa_alignment_max - 1)) { /* p was not the result of a malloca() call. Invalid argument. */ abort (); } /* Determine whether p was a non-NULL pointer returned by mmalloca(). */ - if ((uintptr_t) p & sa_alignment_max) + if (u & sa_alignment_max) { - void *mem = (char *) p - ((small_t *) p)[-1]; + char *cp = p; + small_t *sp = p; + void *mem = cp - sp[-1]; free (mem); } }