In article <11**********************@e56g2000cwe.googlegroups .com>,
"dr******@yahoo.com" <dr******@yahoo.com> wrote:
Hello,
I am running the following code segment in visual studio 2005.
size_t cchSize = 10*sizeof(TCHAR);
LPTSTR temp = (LPTSTR)malloc(cchSize);
temp[0] = '\0';
_tcscat_s(temp, cchSize, _T("hello"));
free(temp);
It fails at the statement -
free(temp)
with the error:
Heap block at 00A57F80 modified at 00A57FC0 past requested size of 38.
If i change _tcscat_s to deprecated _tcscat there is no error. Can
anyone throw some light on this?
I believe that if you put the above code in a main all by itself, the
error will go away as well. If not, then probably _tcscat_s doesn't do
what you think it does and is writing past the requested size.
I can't help but wonder how big a TCHAR is if 10 * sizeof(TCHAR) ends up
equaling 38...
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.