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 hn newest 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. load replies (2) Sharlin|2 months ago Good luck though remembering not to pass one to any function that does expect to find a null terminator. load replies (3)
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. load replies (2) Sharlin|2 months ago Good luck though remembering not to pass one to any function that does expect to find a null terminator. load replies (3)
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. load replies (2)
Sharlin|2 months ago Good luck though remembering not to pass one to any function that does expect to find a null terminator. load replies (3)
kccqzy|2 months ago
ninkendo|2 months ago
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