Mail Archives: djgpp/1999/02/17/15:40:26
At 06:46 PM 2/16/99 PST, you wrote:
>I'm having a problem with a Stack Overflow ( General Protection Error) . I
>Symifyed my program and was told that my errors were }s. I checked over my
>code and found out that all my problems were related to one function.
>
>void unequip_other_weapons(void) {
> int x;
> for(x=0;x<sizeof(PS.weapons_array); x++) {
> if(PS.weapons_array[x] == 2) { PS.weapons_array[x] = 1; }
> }
>}
>
>weapons_array is declared as int weapons_array[10];
>
>Can someone tell me what the problem is, and how I can fix it?
IIRC, sizeof on an array returns its length in terms of sizeof(char), so
this is causing x to go from 0 all the way to 39 (as an int is 4 bytes
under DJGPP). So it's overwriting the end of the array and if it's a local
variable, smashing the stack, otherwise scrogging the heap.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot |http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|
- Raw text -