1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

(MALLOC_ALIGNMENT): Set to __alignof__ (long double) if long double is more aligned than 2 * SIZE_SZ. (misaligned_chunk): Define. (public_rEALLOc, _int_free, _int_realloc): Use it.

This commit is contained in:
Ulrich Drepper
2006-03-02 15:53:19 +00:00
parent 8f6b4d1bb7
commit 073f560e7b

View File

@ -188,7 +188,8 @@
Changing default word sizes: Changing default word sizes:
INTERNAL_SIZE_T size_t INTERNAL_SIZE_T size_t
MALLOC_ALIGNMENT 2 * sizeof(INTERNAL_SIZE_T) MALLOC_ALIGNMENT MAX (2 * sizeof(INTERNAL_SIZE_T),
__alignof__ (long double))
Configuration and functionality options: Configuration and functionality options:
@ -380,7 +381,8 @@ extern "C" {
#ifndef MALLOC_ALIGNMENT #ifndef MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT (2 * SIZE_SZ) #define MALLOC_ALIGNMENT (2 * SIZE_SZ < __alignof__ (long double) \
? __alignof__ (long double) : 2 * SIZE_SZ)
#endif #endif
/* The corresponding bit mask value */ /* The corresponding bit mask value */
@ -1807,7 +1809,11 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/* Check if m has acceptable alignment */ /* Check if m has acceptable alignment */
#define aligned_OK(m) (((unsigned long)((m)) & (MALLOC_ALIGN_MASK)) == 0) #define aligned_OK(m) (((unsigned long)(m) & MALLOC_ALIGN_MASK) == 0)
#define misaligned_chunk(p) \
((uintptr_t)(MALLOC_ALIGNMENT == 2 * SIZE_SZ ? (p) : chunk2mem (p)) \
& MALLOC_ALIGN_MASK)
/* /*
@ -3468,7 +3474,7 @@ public_rEALLOc(Void_t* oldmem, size_t bytes)
Therefore we can exclude some size values which might appear Therefore we can exclude some size values which might appear
here by accident or by "design" from some intruder. */ here by accident or by "design" from some intruder. */
if (__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0) if (__builtin_expect ((uintptr_t) oldp > (uintptr_t) -oldsize, 0)
|| __builtin_expect ((uintptr_t) oldp & MALLOC_ALIGN_MASK, 0)) || __builtin_expect (misaligned_chunk (oldp), 0))
{ {
malloc_printerr (check_action, "realloc(): invalid pointer", oldmem); malloc_printerr (check_action, "realloc(): invalid pointer", oldmem);
return NULL; return NULL;
@ -4282,7 +4288,7 @@ _int_free(mstate av, Void_t* mem)
Therefore we can exclude some size values which might appear Therefore we can exclude some size values which might appear
here by accident or by "design" from some intruder. */ here by accident or by "design" from some intruder. */
if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0) if (__builtin_expect ((uintptr_t) p > (uintptr_t) -size, 0)
|| __builtin_expect ((uintptr_t) p & MALLOC_ALIGN_MASK, 0)) || __builtin_expect (misaligned_chunk (p), 0))
{ {
errstr = "free(): invalid pointer"; errstr = "free(): invalid pointer";
errout: errout:
@ -4628,7 +4634,7 @@ _int_realloc(mstate av, Void_t* oldmem, size_t bytes)
oldsize = chunksize(oldp); oldsize = chunksize(oldp);
/* Simple tests for old block integrity. */ /* Simple tests for old block integrity. */
if (__builtin_expect ((uintptr_t) oldp & MALLOC_ALIGN_MASK, 0)) if (__builtin_expect (misaligned_chunk (oldp), 0))
{ {
errstr = "realloc(): invalid pointer"; errstr = "realloc(): invalid pointer";
errout: errout: