[cfe-dev] bug in clang

Chris Lattner clattner at apple.com
Mon Nov 22 18:00:46 PST 2010


On Nov 22, 2010, at 6:49 AM, Andrew Wells wrote:

> Hi,
>     I was coding a USACO practice problem mhen I came across this bug 
> which causes a Segmentation fault (I am using Fedora 14 x86_64).  Please 
> consider the following code:

Hi Andrew,

Your code is correct.  "character" only has space for 5 characters and you're accessing the 6th.

-Chris

> 
> #include <stdio.h>
> 
> int main ()
> {
> 
>     FILE *fout = fopen ("test.txt", "w");
>     char character[5];
>     int i;
>     for(i = 0; i < 6; i++)
>     {
>         character[i] = 'A'; //This statement causes an error
>     }
> 
> 
> fprintf(fout, "Point 1\n");
> 
>     return (0);
> }
> 
> God bless you,
> Andrew Wells
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 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