This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: Problem with Object Size Checking and reallocarray


On 13/03/18 14:05, Yaakov Selkowitz wrote:
> On 2018-03-13 07:51, Corinna Vinschen wrote:
>> On Mar 12 19:58, Jon Turney wrote:
>>> reallocarray() is annotated in stdlib.h with '__alloc_size(2)
>>> __alloc_size(3)'
>>>
>>> per [1], this doesn't seem to be the correct syntax when the size is the
>>> product of the arguments, and the last alloc_size seems to be silently
>>> winning.
>>>
>>> If I change this to '__alloc_size((2,3))' (as in the patch attached),
>>> __builtin_object_size doesn't seem to be a compile-time constant anymore,
>>> and so memcpy() evaluates differently, so it's hard to be sure that's
>>> actually correct...
>>>
>>> [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
>>
>> Yaakov, care to comment and push if the patch is ok?
> 
> Thanks, pushed.
> 

This doesn't work at all.  I get:

warning: alloc_size parameter outside range [-Wattributes]

There's too many levels of parenthesis around the parameters, so it
expands to
void *reallocarray(void *, size_t, size_t)
__attribute__((__alloc_size__((2,3))));

And this causes all the testsuites to start failing due tot he warning.

To silence the warning it needs to be __attribute__((__alloc_size__(2,3)))

I'm not sure how you achieve that, given the macro expansion going on here.

R.


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