Hello there,
In this code below, even if i put 1 or any number as argument in the malloc function, the result is always correct, no matter what. But if i remove it, result is unreadable. What happen with malloc?
The program concatinates 2 strings.
EDIT: I use gcc on Ubuntu
malloc probably get more memory from the OS than it actually needs (the extra memory can be used for later allocations) so that's probably why reading and writing outside the limit of what you requested doesn't crash.
EDIT: one problem with your program is that you forgot to place a null termination character at the end of the new string.