It's good to see some publicity around this, my experience from Stack Overflow tells me few C programmers know about these details.<p>That said, if the article's code would have appeared on Stack Overflow, I wouldn't be able to prevent myself from also saying:<p>The author's suggested replacement, the C++ template function (!) strcpy_safe(), is not so hot in my opinion.<p>It uses strncpy(), which is record-oriented and thus will <i>always</i> fill all its n bytes. If you do:<p><pre><code> char bigbuf[1024];
strncpy(bigbuf, "foo", sizeof bigbuf);
</code></pre>
Then strncpy() will happily 0-fill <i>all</i> of that buffer space, which of course is completely pointless and just a waste of precious cycles. This is because it treats the buffer as a "record", and insists to initialize all of it.<p>This is the "flip side" of the logic that prevents it from 0-terminating if the string fills the buffer; since the buffer is a record with a known size, and not really a C string, it doesn't need to be terminated, right? Heh.<p>Also, POSIX reserves the namespace of functions whose names start with "str". I'm not 100% sure how well this applies to C++, but it seems prudent to avoid defining your own function with a name like that.