I support a rather large snippet of old code that still uses strncpy. Now I have begun the process of replacing use strncpywith a safe copy of it strncpy_s. I noticed that it strncpy_sfills the destination buffer using values of -2, but only in debug builds! There are no gaps in the release build.
For instance:
char buffer[3];
memset(buffer, 0, sizeof(buffer));
strncpy_s(buffer, sizeof(buffer), "a", _TRUNCATE);
int i = buffer[2];
MSDN docs don't mention this add-on, and in my case this is really what I don't want, because my old code relies on the fact that the zeroed portions of the buffer remain nullified and are not overwritten while copying lines.
strncpy_s ?
, Visual Studio 2010, Visual Studio 2013.