Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The issue is that strncpy() isn't a str___() function, despite its name. It's a 0x00-padded memcpy.


The 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.


But 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.


No, 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.


[flagged]


> Have you considered giving reading comprehension a try?

Don't do this.


Then don’t demand it by wilfully misunderstanding comments in order to “well actually” them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: