Where did you get this code? Chat GPT?
What is it supposed to do?
You did not fill your buffer. Why would yiu like to print it?
Sorry, but to me it makes no sense...
Sometimes it is very difficult to see whether the code is written by chatGPT (=nonsense) or by someone that really knows what he/she is doing, specially if it is only a snippet.
The use of malloc is rather rare on this forum. And not really newbee stuff. So before trying to understand your code (I am not really familiar with malloc) I wanted to rule out the option that the code was complete nonsense...(and I would be wasting my time).
Anyway, your problem is solved so that is great!