logoalt Hacker News

thihttoday at 12:11 PM3 repliesview on HN

> In place of strncpy, Linux kernel code should use strscpy() for NUL terminated destinations, strscpy_pad() for NUl-terminated destinations with zero-padding, strtomem_pad() for non-NUL-terminated fixed-width fields, memcpy_and_pad() for bounded copies with explicit padding, or memcpy() for known-length memory copies

What a nightmare, does it have to be so convoluted?


Replies

MarkMarinetoday at 1:02 PM

Performance. A safe Swiss Army knife function that did most of this would be slow because of the internal branching you’d need to be safe, and because there is developer intent in the selection of these functions. I’d rather have the choice and clear dev intent when I see the function used when reading code.

bobmcnamaratoday at 3:25 PM

> does it have to be so convoluted?

Getting strncpy right always has been

hahn-kevtoday at 2:15 PM

Couldn't they at least give them better names?