开发者

Calloc providing a pointer that begins inside already allocated memory?

I'm getting some kind of pointer collision,

Basically, in one function I do,

a = calloc(1,28); // gives me 0x100100d10

Then pretty soon in a subfunction I do,

b = calloc(1,16); // gives me 0x100100d20;

first address + 28 is 0x0.开发者_开发技巧.d2C, ie, extends over the pointer provided in the second calloc...

Whats going on here?

Pointer values are from printf, not gdb.


If this is really happening as you describe, then you have corrupted the heap by writing outside the bounds of an allocated block (or perhaps even by using an uninitialized pointer or pointer to already-freed memory), thus invoking undefined behavior. The tool valgrind can probably help you track the problem down, or if your program isn't too big, you can simply search by hand for invalid pointer usage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜