3 ms·
I hope you meant strlen in place of sizeof
by ot 16y ago
I hope you meant strlen in place of sizeof
- Luyt 16y agoor sizeof(dst), and not forgetting dst[sizeof(dst)-1]='\0';
- wladimir 16y agoThat's why strlcpy is safer than strncpy, it makes sure that the destination string will always be zero-terminated.
- jazzyb 16y agoMost people use sizeof when they are copying between static buffers on the stack. Strlen would be just as bad of an idea in this example because they're using the src buffer as the limit on the copy rather than the dst buffer which is still vulnerable to overflow. Should be: strncpy(dst, src, sizeof(dst)-1); Edit: bad code