3 ms·
Here I was thinking that we should all be ashamed of the existence of strlen & strcpy etc as they are simply security holes masquerading as something else. Is t
by harry8 6y ago
Here I was thinking that we should all be ashamed of the existence of strlen & strcpy etc as they are simply security holes masquerading as something else. Is that wrong? Do they have a place?
strnlen(const char* s, size_t maxlen);
strncpy(char* dest, const char* src, size_t n);
Is this a silly concern in this context? Seems a lot of people still don't know the old school libc functions are a disaster and should not be used. (And you have to be careful with the ones with a maximum size as well).
Here's how to do something wrong you should never do..? Thoughts?
- IshKebab 6y agoYou're right, modern code definitely shouldn't use them. But there's a lot of code that isn't remotely modern so we still have to support them. Also nobody ever bothered to add a better string library to the standard C library so lots of people who write C just take the lazy route and use `strlen` etc.
- saagarjha 6y agoYou probably shouldn't be blindly using the suggestions you provided either.
- deleted 6y ago[deleted]