public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/arm/morello/main] cheri: malloc: fix alignment logic in obstack
Date: Wed, 26 Oct 2022 15:11:33 +0000 (GMT)	[thread overview]
Message-ID: <20221026151143.24A8D3854170@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a2305153c665db237f063efee5b25303cb4e6899

commit a2305153c665db237f063efee5b25303cb4e6899
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Mar 16 14:07:04 2022 +0000

    cheri: 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.

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 <string.h>

             reply	other threads:[~2022-10-26 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 15:11 Szabolcs Nagy [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-08-05 19:35 Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026151143.24A8D3854170@sourceware.org \
    --to=nsz@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).