Curl removes all calls to strcpy

104 points by groctel


snej

I know it’s hard to make changes in a large, old codebases, but it would have been so much better to change the string type rather than the parameters for copying. So instead of making every copy pass const char *src, size_t slen, change the string type from const char* to struct {const char *src; size_t slen;}. (This is what C++ calls string_view, Go calls slice, Rust calls str, etc.)

After all, if you have to know a string's length in advance when you copy it, what’s the point of the null byte at the end? You were probably given the length along with the pointer (otherwise you'd have to make a slow strlen call to get it, before you could call safe_strcpy) so why not just package that length up with the pointer?

dzwdz

strcpy however, has its valid uses and it has a less bad and confusing API.

Contrast this with strcpy: a niche function you don't need :)

FWIW I agree with Daniel on this one.