| ▲ | Sharlin 20 hours ago | |||||||
Good luck though remembering not to pass one to any function that does expect to find a null terminator. | ||||||||
| ▲ | kevin_thibedeau 19 hours ago | parent | next [-] | |||||||
Ignore the prefix and always treat strncpy() as a special binary data operation for an era where shaving bytes on storage was important. It's for copying into a struct with array fields or direct to an encoded block of memory. In that context you will never be dependent on the presence of NUL. The only safe usage with strings is to check for NUL on every use or wrap it. At that point you may as well switch to a new function with better semantics. | ||||||||
| ||||||||
| ▲ | integralid 18 hours ago | parent | prev | next [-] | |||||||
That's not a problem with strncpy, right? Fixed width records are a thing of the past, and even then it was only used for on-disk storage. | ||||||||
| ▲ | andrepd 19 hours ago | parent | prev [-] | |||||||
Seriously. We have type systems and compilers that help us to not forget these things. It's not the 70s anymore! | ||||||||
| ||||||||