https://bugs.kde.org/show_bug.cgi?id=466104

--- Comment #2 from Paul Floyd <pjfl...@wanadoo.fr> ---
More details. glibc memalign is here
https://elixir.bootlin.com/glibc/glibc-2.37/source/malloc/malloc.c#L3504

  if (alignment <= MALLOC_ALIGNMENT)
    return __libc_malloc (bytes);

  /* Otherwise, ensure that it is at least a minimum chunk size */
  if (alignment < MINSIZE)
    alignment = MINSIZE;

  /* If the alignment is greater than SIZE_MAX / 2 + 1 it cannot be a
     power of 2 and will cause overflow in the check below.  */
  if (alignment > SIZE_MAX / 2 + 1)
    {
      __set_errno (EINVAL);
      return 0;
    }

What are those macros?
#define MALLOC_ALIGNMENT (2 * SIZE_SZ < __alignof__ (long double) \
                          ? __alignof__ (long double) : 2 * SIZE_SZ)

SIZE_SZ is the size of size_t, 8 on 64bit and 4 on 32bit.

alignof long double is 4 on x86 16 on amd64 16 on aarch64 8/16 for MIPS32/64
and 16 for PPC. I don't think that the condition is true on any platform we
support so this is 8 on 32bit and 16 on 64bit.



MINSIZE, another macro rabbit hole

#define MINSIZE  \
  (unsigned long)(((MIN_CHUNK_SIZE+MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK))

MIN_CHUNK_SIZE is 16/32 on 32/64 bit systems.
MALLOC_ALIGN_MASK is MALLOC_ALIGNMENT - 1, so 7 or 15
I make that 16 for 32bit systems and 32 for 64bit systems.

SIZE_MAX is in stdint.h. I can add a VKI_SIZE_MAX.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to