C compiler bug (optimizer), Irix 3.3.1

Mark V. Meuer meuer at cs.umn.edu
Sat May 4 01:11:08 AEST 1991


In <9105021249.16330 at godzilla.cgl.rmit.oz.au> mg at GODZILLA.CGL.RMIT.OZ.AU (Mike Gigante) writes:


>In the following code:

>void
>  drawbbox(struct bbox bb)
>{
>  float v[7][3];
>  int i;

>  /*
>   * a close enough approximation...
>   */
...
[stuff deleted to save bandwidth]
...
>  v[7][0] = bb.x1;
>  v[7][1] = bb.y1;
>  v[7][2] = bb.z2;  (**)

>  bgnclosedline();
>  for(i=0; i < 8; i++)
>    v3f(v[i]);
>  endclosedline();
>}

>I get an incorrectly draw bbox. 

>From the looks of it, you should get a segmentation fault.  You are
declaring v to have 7 elements, yet you are filling it with eight
(0-7). 

> Ok, so I did the following:


>  bgnclosedline();
>  for(i=0; i < 8; i++) {
>    v3f(v[i]);
>    printf("bbox: %f %f %f\n", v[i][0], v[i][1], v[i][2]);
>  }
>  endclosedline();

>and lo and behold, it tells me that the Z value for the last point is
>wrong while for the second last point, it is correct. A quick look at
>the assignment code shows that in both positions, (see * & **), reveals
>that this should *not* happen.

Ah, but since the last point is beyond the declared end of the array,
it is not defined what will happen.  Except, of course, that whatever
will happen will be bad.



>Mike Gigante,
>ACGC
>Royal Melbourne Institute of Technology


-mark
-- 
Mark Meuer   <><    |  The Geometry Center  |  meuer at geom.umn.edu
"My guess is that object-oriented programming will be in the 1980's what
structured programming was in the 1970's.  Everyone will be in favor of it.
Every manager will pay lip service to it.  Every programmer will practice it



More information about the Comp.sys.sgi mailing list