I'm having a problem with the following piece of code throwing warnings and hoping you could help me:
fprintf (fp, "%dd%d+%d ", pMobIndex->mana[DICE_NUMBER],
DICE_NUMBER
is defined in my header file as 0.
Obviously, 0 is not exceeding the size of the array.
The array is defined as.
int mana[2];
I have absolutely no idea why it would be doing this, as 0 is clearly within the bounds of the array. Half of my engines code is throwing these array bound errors now, I've got about 30 of them, and NONE of them make sense to me.
Here is the output from make:
gcc -O3 -s -Wall -c -o obj/olc_save.o olc_save.c
olc_save.c: In function 'save_mobile':
olc_save.c:234:13: warning: array subscript is above array bounds [-Warray-bounds]
fprintf (fp, "%dd%d+%d ", pMobIndex->mana[DICE_NUMBER],
^
it also happens:
db1.c: In function 'create_mobile':
db1.c:2056:30: warning: array subscript is above array bounds [-Warray-bounds]
+ pMobIndex->mana[DICE_BONUS];
and
olc_act.c: In function 'medit_manadice':
olc_act.c:6500:15: warning: array subscript is above array bounds [-Warray-bounds]
pMob->mana[DICE_BONUS] = atoi (bonus);
The definition in my header file:
/* dice */
#define DICE_NUMBER 0
#define DICE_TYPE 1
#define DICE_BONUS 2
I'm aware DICE_BONUS
will be (realizing it only now) but I for the life of me cannot figure out why DICE_NUMBER
is.
D'oh. The problem is that the third integer output there on the fprintf
is DICE_BONUS
but its on another line, I thought the compiler was warning me about DICE_NUMBER
, it was warning me about BONUS.