5 ms·
People keep on misusing strncpy which is why people keep blogging about it. I wrote about it two years ago after running across one too many abuses: https://ra
by brucedawson 11y ago
People keep on misusing strncpy which is why people keep blogging about it. I wrote about it two years ago after running across one too many abuses:
https://randomascii.wordpress.com/2013/04/03/stop-using-strncpy-already/ https://randomascii.wordpress.com/2013/04/03/stop-using-strn...
I tried to give alternatives. Calling strncpy and then manually null-terminating is not a good alternative. Creating a wrapper that does this is better. That wrapper could optionally abort the program on string truncation.
And, probably more importantly, a template wrapper can infer the destination size, thus getting rid of the error-prone specification of the destination size (I have seen it specified incorrectly many times).
You'd be mad to use strncpy when better alternatives are so easy to find or create.