Unjustified warning?

Martin Sebor msebor@gmail.com
Fri Dec 15 16:04:00 GMT 2017


On 12/15/2017 04:55 AM, Marcel Keller wrote:
>> The warning isn't caused by the explicit memset but rather by GCC
>> introducing one within the loop.  I'm not sure that the warning
>> itself should be considered a bug.  If the function is called with
>> length greater than or equal to 32 it will overflow.  So I'd say
>> the warning is helpful in pointing it out.  What's not helpful
>> is the missing location information, compounded by the fact that
>> the only memset call in the source code isn't what causes it.
>>
>> To avoid the warning make sure foo() calls avx_memzero with
>> a length of at most the size of bar.
>
> Thank you for the clarification. If I limit the length as in the code
> attached, I still get the warning however.

To avoid writing past the end of bar length must be at most sizeof
bar:

   avx_memzero(bar, std::min (sizeof(bar), t));

Martin



More information about the Gcc-help mailing list