Mail Archives: djgpp/1999/02/16/23:10:52
Paradox 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?
sizeof(weapons_array) == 40 (10 * sizeof(int), which is 4). Iterating
to element 40 of the array is wrong.
You meant to limit x at
(sizeof(PS.weapons_array)/sizeof(PS.weapons_array[0])). (More
change-resistant than hardcoding int.)
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -