[PATCH] libio: Add small optimization on fmemopen

Florian Weimer fweimer@redhat.com
Wed Sep 21 18:23:00 GMT 2016


On 09/21/2016 08:17 PM, Adhemerval Zanella wrote:
>
>
> On 21/09/2016 14:22, Paul Eggert wrote:
>> On 09/21/2016 07:05 AM, Adhemerval Zanella wrote:
>>> +      clen += len;
>>
>> That might cause problems , as the C standard says you can't access a flexible array member past the last byte that is properly aligned for the containing structure, and GCC relies on this when generating code (see GCC bug 66661). One way to work around the problem is to change the earlier:
>>
>> +  size_t clen = sizeof (fmemopen_cookie_t);
>>
>> to:
>>
>> +  size_t clen = sizeof (fmemopen_cookie_t) + _Alignof (fmemopen_cookie_t) - 1;
>>
>> This may overallocate a bit, but that's OK here.
>>
>
> Thanks for pointing this out, I think this is the safe approach regarding
> Florian comment #10 and #11.  I will change it.

Please don't, it's a defect in the standard (and GCC"s Address Sanitizer 
has a bug as well).

Florian



More information about the Libc-alpha mailing list