Re: GCC Bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 30 Jan 2004 23:03:49 +0100, Wolfgang Meyerle wrote:
> Please try out the following code snipet (not very large if you leave
> the commented lines away...
> 
> You can compile it with gcc -g 3d.c -lm -lvga -o 3d
> 
> If you try it out it produces a segmentation fault... (Why???)
> If you declare the variable count a little bit further down it doesn't
> produce the segmentation fault. After I used ddd to locate the failure
> it told me that the variable count is overwritten with strange numbers
> that are out of the program memmory.
> 
> I'm using gcc 3.2.2 on slackware 9.0 
> 
> Isn't that strange ???
> 
> If you have any Idea what's going on there please let me know
  ...<snip>...
> struct point3d points[4];
  ...<snip>...
> points[4].x=-412;
> points[4].y=-50;
> points[4].z=0.8;

You declare points to be an array of 4 point3d structs, but then you
access element 4 (and elements 5, 6, and 7). So you're stomping all over
memory past the end of the array. That's where your 'strange numbers' come
from.

So it's a program bug, not GCC.

S>

-- 
<<< Eagles may soar, but weasels don't get sucked into jet engines >>>
10:15pm up 50 days 4:43, 19 users, load average: 0.20, 0.12, 0.14
Registered Linux User #232457 | LFS ID 11703

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux