Some of sizeof() bugs fixed.

You cannot call sizeof() for dynamically allocated memory. It will just return the size of pointer, not the size of allocation.

Also strlen() counts only characters, while size parameter of snprintf() also counts the final null byte.