top | item 46433897

(no title)

ufo | 2 months ago

A big footgun with strncpy is that the output string may not be null terminated.

discuss

order

kccqzy|2 months ago

Yeah but fixed width strings don’t need null termination. You know exactly how long the string is. No need to find that null byte.

ninkendo|2 months ago

Until you pass them as a `char *` by accident and it eventually makes its way to some code that does expect null termination.

There’s languages where you can be quite confident your string will never need null termination… but C is not one of them.

Sharlin|2 months ago

Good luck though remembering not to pass one to any function that does expect to find a null terminator.