4 ms·
Actually, I think it's true that "If you swap out every use of strcpy for a correct use of strncpy, you'll have fewer bugs." Any use of strncpy that breaks wou
by dllthomas 10y ago
Actually, I think it's true that "If you swap out every use of strcpy for a correct use of strncpy, you'll have fewer bugs."
Any use of strncpy that breaks would also have broken if strcpy had been used instead, and there exist some situations where strncpy would not break while strcpy would; for instance, if we just inspect a prefix of the resulting string.
That said, it's certainly the case that most breaking uses of strcpy, if naively replaced with strncpy, still break.
- geofft 10y ago> Actually, I think it's true that "If you swap out every use of strcpy for a correct use of strncpy, you'll have fewer bugs." Yes, I agree that this statement is true. But my claim is that this is not what the article means by "safer", and the article's definition of "safer" is more useful. That is, people who are saying "The article is wrong because it is possible to use strncpy correctly in cases where strcpy was not being used correctly" are not disagreeing with the article so much as talking past it.
- dllthomas 10y agoFair enough.