开发者

C++ Code works in 32 bit but fails in 64 bit with heap corruption

开发者 https://www.devze.com 2023-03-13 14:40 出处:网络
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.

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]) { ... }

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号