Quote:
Originally posted by AnthonyMai
It is is not WILL, it is COULD. Actually in the specific case of the OP it is WOULD NOT.
I don't like the way the OP allocate only strlen() bytes. But it is only a small possibility that you could overwrite the memory by one byte (a 12.5% possibility) this way.
When memory is allocated, it is seldom allocated to the exact size specified. It will allocate memory suitably aligned and sized for the biggest alignment element, which is normally 8 bytes. So you can expect that the pointer to the start of the memory is 8 bytes aligned, and the size is a multiple of 8 bytes.
In the case of OP, the string length is 15 bytes, so 16 bytes or more will be allocated. Copying 15+1 bytes hence will not cause any problem.
Wow, a word such as "will" makes you write so many paragraphs of really nothing important.