4 ms·
You get a compile error. And this is progress. I have fixed code that looked something like this: strncpy(dst, sizeof(dst), src); data[sizeof(dst)-1]
by brucedawson 8y ago
You get a compile error.
And this is progress. I have fixed code that looked something like this:
strncpy(dst, sizeof(dst), src);
data[sizeof(dst)-1] = 0;
See the bug? Of course not, because it's not visible, but I've seen this pattern used where dst is a pointer. This means that four or eight bytes (three or seven if you don't count the null terminator) gets copied, regardless of how many bytes dst points to. With strcpy_safe an attempt to copy to dst would not work and the developer would have to fix their code.
Every mistake that can be made, will be made.