This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug malloc/20137] aligned_alloc should fail for bad size / alignment [DR#460]
- From: "fweimer at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 25 May 2016 11:11:41 +0000
- Subject: [Bug malloc/20137] aligned_alloc should fail for bad size / alignment [DR#460]
- Auto-submitted: auto-generated
- References: <bug-20137-131 at http dot sourceware dot org/bugzilla/>
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.