And you always need a Borland compiler around dude!
Announcement
Collapse
No announcement yet.
C help needed
Collapse
X
-
Ehrm, writing outside the allocated memory usually means that you are writing in memory management data, so no wonder why you chrash
With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.
Steven Weinberg
Comment
-
Well, that too gives a core dump. Wonder actually what system he is using since I usually get the reason why I get a core dump - that is something more informing than "Aborted (core dumped)".Originally posted by Kuciwalker
It should just segfault though...With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.
Steven Weinberg
Comment
-
No. The way it works is that the C lib for efficiency will allocate a big chunk of memory (one or more pages) at a time, and then give you little peices each time you call malloc.Originally posted by Kuciwalker
It should just segfault though...
The malloc implementation is free to use some of its allocated memory for control structures, for example a linked list of allocated memory. For example the elements of this list could be interspersed with the actual malloced memory.
So if you allocate 16 bytes, but write 20 to the pointer you get, you will, say, overwrite the linked list head of the following element in malloc's linked list. So when you call free() it will find an invalid data structure.
For debugging, and depending on the compiler, you can instruct the compiler to link against an alternative malloc implementation which is implemented to discover any corruption sooner.http://www.hardware-wiki.com - A wiki about computers, with focus on Linux support.
Comment
-

Comment