C++ Code works in 32 bit but fails in 64 bit with heap corruption
I am new to C++ and need help in resolving the heap corruption issue on 64 bit. Below is the code that works on 32 bit but not on 64 bit.
#define a 3
#define b 4
char *c[b-a+1];
//some allocation code to char *c[b-a+1]
//destructor code that fails
for (x = a; x <= b; x++) {
if c([x-a]){
char * y =(char*)c[x-a];
free(y);
c[x-a]=null;
}
}
Pleas开发者_Python百科e note this is not my code, just something i inherited and need to fix.
Any help is appreciated.
Thanks,
in your code b-a+1 = 2
so ..
x = a it means x = 3
so ... x <= b means while <= 4, but array size is 2. it's a runtime err
and also is there any declaration of variable x ?
if c([x a]) { ... } is it correct syntax ? maybe you want to say if (c[x-a]) { ... }
精彩评论