From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 926813851522; Thu, 27 Oct 2022 13:49:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 926813851522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666878560; bh=CgE9De1HOs3/RKL0yijpr0dbyWUQ8gMX4GUh37SA0fg=; h=From:To:Subject:Date:From; b=IgNKeNoy5zN64h5DoHpMpsMV43EV4cJhb2e5svxp4mPObuyzYZNBtXccga5T5aQ3h VPEEbjVOUJ8CISkKsuLhXL0WdqDQE2pipobLjNrnPSNfLK1pkDPnddCKRK+OoWBa+9 tsVpR4LaY3MHCl0gEZFe1L8bhim28Jnw/M8dD/Ww= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] malloc: Fix alignment logic in obstack X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: a05d3855313903679c604143cdc00f803d142a71 X-Git-Newrev: 01359abab8f5b7f44e6aa4260eb5f3f878d7ff4a Message-Id: <20221027134920.926813851522@sourceware.org> Date: Thu, 27 Oct 2022 13:49:20 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=01359abab8f5b7f44e6aa4260eb5f3f878d7ff4a commit 01359abab8f5b7f44e6aa4260eb5f3f878d7ff4a Author: Szabolcs Nagy Date: Wed Mar 16 14:07:04 2022 +0000 malloc: Fix alignment logic in obstack If sizeof(ptrdiff_t) < sizeof(void*) the alignment logic was wrong: incorrectly assumed that base was already sufficiently aligned. Use more robust alignment logic: this one should work on any target. Note: this is an installed header so it must be namespace clean and portable hence it uses unsigned long for the alignment offset. Diff: --- malloc/obstack.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/malloc/obstack.h b/malloc/obstack.h index 4b01cdfe4d..1cf18e5464 100644 --- a/malloc/obstack.h +++ b/malloc/obstack.h @@ -116,22 +116,9 @@ # define PTR_INT_TYPE ptrdiff_t #endif -/* If B is the base of an object addressed by P, return the result of - aligning P to the next multiple of A + 1. B and P must be of type - char *. A + 1 must be a power of 2. */ - -#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A))) - -/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case - where pointers can be converted to integers, aligned as integers, - and converted back again. If PTR_INT_TYPE is narrower than a - pointer (e.g., the AS/400), play it safe and compute the alignment - relative to B. Otherwise, use the faster strategy of computing the - alignment relative to 0. */ - -#define __PTR_ALIGN(B, P, A) \ - __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \ - P, A) +/* Align P to the next multiple of A + 1, where A + 1 is a power of 2, + A fits into unsigned long and P has type char *. */ +#define __PTR_ALIGN(B, P, A) ((P) + (-(unsigned long)(P) & (A))) #include