Hey,
When receiving data through a socket using recv, I've noticed that, with:
char buffer[4]; memset(buffer, 0, 4); recv(socket, buffer, 4, 0);
I receive
mesgx��
"mesg" being what I sent, with some random characters appended.
If I use
char * method = (char *) malloc(4); memset(buffer, 0, 4); recv(socket, buffer, 4, 0);
instead, I receive
mesg
So there's no random stuff appended to my string. I figured out that if I use char[5] instead it works as well, but I do not really understand why. Does malloc(4) really allocate 5 bytes, the fifth being a NUL?
Regards,
x3ro