[Bug malloc/20137] aligned_alloc should fail for bad size / alignment [DR#460]
fweimer at redhat dot com
sourceware-bugzilla@sourceware.org
Wed May 25 11:11:00 GMT 2016
https://sourceware.org/bugzilla/show_bug.cgi?id=20137
--- Comment #3 from Florian Weimer <fweimer at redhat dot com> ---
To be clear, the use case I'm thinking about is allocating storage for an
object of this type:
struct flexible
{
_Decimal128 value;
char formatted[];
};
Doing something like this (with error checking) looks reasonable to me:
size_t length = strlen (formatted);
struct flexible *p = aligned_alloc (_Alignof (struct flexible),
offsetof (struct flexible, formatted)
+ length + 1);
p->value = value;
memcpy (p->formatted, formatted, length + 1);
I'm surprised this isn't recognized as a useful coding pattern.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list