Any function that modifies a string exposes a potential danger: if the destination string buffer is not large enough to contain the resulting string, memory corruption occurs. Here is an example:
// The following puts 4 characters in a // 3-character buffer, resulting in memory corruption WCHAR szBuffer = L""; wcscpy(szBuffer, L"abc"); // The terminating 0 is a character too!
The problem with the
wcscpy functions (and most other string manipulation functions) is that they do not accept an argument specifying the maximum size of the buffer, and therefore, the function doesn’t know that it is corrupting memory. Because the function doesn’t know that it is corrupting memory, it can’t report ...