alx-0029r5 - Restore the traditional realloc(3) specification

Martin Uecker ma.uecker@gmail.com
Fri Jun 27 12:54:34 GMT 2025


Am Freitag, dem 27.06.2025 um 10:52 +0200 schrieb Florian Weimer:
> * Alejandro Colomar:
...

> 
> From an implementation perspective, we need clarification that the
> allocation functions (except aligned_alloc) may reduce the alignment of
> the returned pointer to a power of two greater or equal to the requested
> size, for allocation sizes that are less than the fundamental alignment.
> (Some existing implementations already do this today, in violation of
> the standard.)

There is a general rule for all allocation functions:

"The pointer returned if the allocation succeeds is suitably aligned so
that it may be assigned to a pointer to any type of object with a fundamental
alignment requirement and size less than or equal to the size requested."

There is some disagreement whether the "requested size" refers to the 
size argument or the total size.  IMHO it is a reasonable interpretation 
that it refers to the size argument, but if implementation would explict
this this could then break programs that swap arguments (the standard
has no symmetry, it makes clear which is which)

Martin








More information about the Libc-alpha mailing list