Re:The Sad State of C Strings
by efaref on Wednesday February 10, 2016 @06:23AM
(#11071975)
[ Parent
| on HN ]
Good, but I'd do one modification -- always write a null byte at the end. Otherwise you end up with a non-null-terminated string and that's bad.
So,
copy_sz = src_sz < (dest_sz - dest_off) ? src_sz : (dest_sz - dest_off - 1);
...
*dest_end = '\0';