[09/20] malloc: Use uintptr_t in alloc_buffer

Message ID 6ff097d212f61a22d620d5aae268007a4e6cf8c1.1666877952.git.szabolcs.nagy@arm.com
State Committed
Commit 68619ddb3b7e8b64a6b849e4972e67163f7659c3
Headers
Series patches from the morello port |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Szabolcs Nagy Oct. 27, 2022, 3:32 p.m. UTC
  The values represnt pointers and not sizes. The members of struct
alloc_buffer are already uintptr_t.
---
 include/alloc_buffer.h            | 10 +++++-----
 malloc/alloc_buffer_alloc_array.c |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)
  

Comments

Florian Weimer Oct. 27, 2022, 4:15 p.m. UTC | #1
* Szabolcs Nagy via Libc-alpha:

> The values represnt pointers and not sizes. The members of struct
> alloc_buffer are already uintptr_t.
> ---
>  include/alloc_buffer.h            | 10 +++++-----
>  malloc/alloc_buffer_alloc_array.c |  6 +++---
>  2 files changed, 8 insertions(+), 8 deletions(-)

Looks okay.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian
  

Patch

diff --git a/include/alloc_buffer.h b/include/alloc_buffer.h
index be33e8b68c..1c1dbe0a46 100644
--- a/include/alloc_buffer.h
+++ b/include/alloc_buffer.h
@@ -248,9 +248,9 @@  __alloc_buffer_alloc (struct alloc_buffer *buf, size_t size, size_t align)
   if (size == 1 && align == 1)
     return alloc_buffer_alloc_bytes (buf, size);
 
-  size_t current = buf->__alloc_buffer_current;
-  size_t aligned = roundup (current, align);
-  size_t new_current = aligned + size;
+  uintptr_t current = buf->__alloc_buffer_current;
+  uintptr_t aligned = roundup (current, align);
+  uintptr_t new_current = aligned + size;
   if (aligned >= current        /* No overflow in align step.  */
       && new_current >= size    /* No overflow in size computation.  */
       && new_current <= buf->__alloc_buffer_end) /* Room in buffer.  */
@@ -282,8 +282,8 @@  __alloc_buffer_next (struct alloc_buffer *buf, size_t align)
   if (align == 1)
     return (const void *) buf->__alloc_buffer_current;
 
-  size_t current = buf->__alloc_buffer_current;
-  size_t aligned = roundup (current, align);
+  uintptr_t current = buf->__alloc_buffer_current;
+  uintptr_t aligned = roundup (current, align);
   if (aligned >= current        /* No overflow in align step.  */
       && aligned <= buf->__alloc_buffer_end) /* Room in buffer.  */
     {
diff --git a/malloc/alloc_buffer_alloc_array.c b/malloc/alloc_buffer_alloc_array.c
index d8c08d03ea..b5f32bb630 100644
--- a/malloc/alloc_buffer_alloc_array.c
+++ b/malloc/alloc_buffer_alloc_array.c
@@ -23,12 +23,12 @@  void *
 __libc_alloc_buffer_alloc_array (struct alloc_buffer *buf, size_t element_size,
                                  size_t align, size_t count)
 {
-  size_t current = buf->__alloc_buffer_current;
+  uintptr_t current = buf->__alloc_buffer_current;
   /* The caller asserts that align is a power of two.  */
-  size_t aligned = ALIGN_UP (current, align);
+  uintptr_t aligned = ALIGN_UP (current, align);
   size_t size;
   bool overflow = __builtin_mul_overflow (element_size, count, &size);
-  size_t new_current = aligned + size;
+  uintptr_t new_current = aligned + size;
   if (!overflow                /* Multiplication did not overflow.  */
       && aligned >= current    /* No overflow in align step.  */
       && new_current >= size   /* No overflow in size computation.  */