Fettle
Fettle

Reputation: 11

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.

Upvotes: 1

Views: 185

Answers (1)

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215387

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.

Upvotes: 4

Related Questions