4 ms·
The issue is that strncpy() isn't a str___() function, despite its name. It's a 0x00-padded memcpy.
by torstenvl 4y ago
The issue is that strncpy() isn't a str___() function, despite its name. It's a 0x00-padded memcpy.
- masklinn 4y agoBut it's not an str* function, it's an strn* function. And most (though not all, that would be too easy) work on fixed-size (hence the n) nul-padded strings.
- torstenvl 4y agoNo, it isn't a string function of any kind. "A string is a contiguous sequence of characters terminated by and including the first null character." § 7.1.1. Calling a bespoke byte-sequence data structure a "string" is inaccurate. Treating strncpy() as a string function is erroneous and can easily lead to memory corruption.
- cesarb 4y agoThe output side of strncpy() might not be a str___() function, but AFAICS the input side of strncpy() is clearly a str___() function, since it stops reading (but not writing) at the first NUL byte.
- deleted 4y ago[deleted]