[cfe-dev] -Warray-bounds false positive?
Ted Kremenek
kremenek at apple.com
Thu Aug 25 14:59:26 PDT 2011
No, the warning is legit. sizeof() returns the size in bytes, not elements. This is an array of doubles.
On Aug 25, 2011, at 2:22 PM, Jordy Rose wrote:
>
> On Aug 25, 2011, at 14:00, Sean McBride wrote:
>
>> Hi all,
>>
>> I'm not enough of a language lawyer to be 100% sure, but:
>>
>> -----
>> int main (void)
>> {
>> double foo[4096];
>> ((char *)(foo))[(sizeof(foo)-1)] = '\0';
>>
>> return 0;
>> }
>> -----
>>
>> test.cp:4:12: warning: array index of '32767' indexes past the end of an array (that contains 4096 elements) [-Warray-bounds]
>> ((char *)(foo))[(sizeof(foo)-1)] = '\0';
>> ^ ~~~~~~~~~~~~~
>>
>> Is a false positive, right?
>
> Yes. File a bug? :-)
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list