News for hackers. Stuff that matters.
Re:Best aspects of C by Gibbon1 on Wednesday November 18, 2020 @03:37AM (#25134434)
Yeah used naively strncpy leaves you an unterminated string. Also like all of them it's up to the caller to predetermine if they will fail if called. So instead of having the checks in one place inside the string function. You have them scattered all over the code if at all.
Re:Best aspects of C by WalterBright on Wednesday November 18, 2020 @07:09AM (#25135886)
The irony of strncpy is it's supposed to eliminate memory corruption errors, but instead is a prolific source of them.
Re:Best aspects of C by Gibbon1 on Wednesday November 18, 2020 @11:52PM (#25146354)
I think I read somewhere the provenience of strncpy was to copy strings into a fixed length field which is why it has the deranged behavior of not terminating the string. Think file systems where the max file name is 8 characters. Or compilers that truncated variable names at 31.