Jordy et al,<br><br>The check *should* be accounting for the array being cast to char*... not sure why it isn't (and in the middle of trying to refactor ActOnFunctionDeclarator). When the bug is filed you can assign it it me, as I've already done a lot of work on improving -Warray-bounds and would like to know/dig into why the false positive is triggering.<br>
<br>Cheers,<br>Kaelyn<br><br><div class="gmail_quote">On Thu, Aug 25, 2011 at 3:12 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Ah, you're right.  We should adjust the array size in the warning based on the pointer type being accessed.<br>
<div><div></div><div class="h5"><br>
On Aug 25, 2011, at 3:01 PM, Jordy Rose wrote:<br>
<br>
> But it's been casted to char *. This is equivalent to this code:<br>
><br>
> double foo[4096];<br>
> char *bar = (char *)foo;<br>
> bar[sizeof(foo)-1] = '\0';<br>
><br>
> I mean, it's probably a bad idea, but it's not an out-of-bounds error.<br>
><br>
><br>
> On Aug 25, 2011, at 14:59, Ted Kremenek wrote:<br>
><br>
>> No, the warning is legit.  sizeof() returns the size in bytes, not elements.  This is an array of doubles.<br>
>><br>
>> On Aug 25, 2011, at 2:22 PM, Jordy Rose wrote:<br>
>><br>
>>><br>
>>> On Aug 25, 2011, at 14:00, Sean McBride wrote:<br>
>>><br>
>>>> Hi all,<br>
>>>><br>
>>>> I'm not enough of a language lawyer to be 100% sure, but:<br>
>>>><br>
>>>> -----<br>
>>>> int main (void)<br>
>>>> {<br>
>>>>    double foo[4096];<br>
>>>>    ((char *)(foo))[(sizeof(foo)-1)] = '\0';<br>
>>>><br>
>>>>    return 0;<br>
>>>> }<br>
>>>> -----<br>
>>>><br>
>>>> test.cp:4:12: warning: array index of '32767' indexes past the end of an array (that contains 4096 elements) [-Warray-bounds]<br>
>>>>     ((char *)(foo))[(sizeof(foo)-1)] = '\0';<br>
>>>>               ^      ~~~~~~~~~~~~~<br>
>>>><br>
>>>> Is a false positive, right?<br>
>>><br>
>>> Yes. File a bug? :-)<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> cfe-dev mailing list<br>
>>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>><br>
><br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>