3 ms·
You think that *((char *) mempcpy (dst, src, n)) = '\0'; is a good solution then? Also, I don't know where this 'srlcpy silently fails' meme comes from. It
by anon1385 13y ago
You think that
*((char *) mempcpy (dst, src, n)) = '\0';
is a good solution then?
Also, I don't know where this 'srlcpy silently fails' meme comes from. It's your responsibility to check the return value. It only 'silently fails' if you don't check. You can argue about whether it is a good idea or not to make client code responsible for that kind of thing but it is the C philosophy. If you think string copy functions should call abort on failure then, like Theo says in the OP, implement that and submit patches to all those projects using strcpy.
- adobriyan 13y ago> mempcpy For chain copying? Why not.
- saurik 13y agoThe reality is that both strcpy and strlcpy require the person using the API to use it correctly in order to not end up with a buggy program; but, in the real world, people hype strlcpy as being fundamentally safer than strcpy, and so if you actually look into how people use strlcpy no one ever checks its return value (even projects like OpenSSH). For more on this (and a specific ludicrous example from OpenSSH where someone spent the time to write a comment above the strlcpy about truncation and yet still didn't actually bother to check the return value of the function), please see this response I made to someone else: https://news.ycombinator.com/item?id=6940724 https://news.ycombinator.com/item?id=6940724