This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] libio: Add small optimization on fmemopen



On 21/09/2016 15:23, Florian Weimer wrote:
> 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).

I do not have a strong opinion here, my idea to use this workaround is 
to avoid possible issues with faulty compilers.  However, if the
consensus is to not push this forward, I can use my original patch.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]