I have a function
void ModifyString2 (WCHAR *szString)
{
int nLen = wcslen (szString);
wcscat_s(szString, MAX_STRING_SIZE, L"-Modified" );
}
I am calling this function from main function.
void main ()
{
WCHAR szString [MAX_NAME_LENGTH] ;
wcscpy_s(szString, MAX_NAME_LENGTH, L"This is Some String");
printf ("Before Call String Value=[%s]", szString);
ModifyString2(szString);
printf ("Before Call String Value=[%s]", szString);
}
When I debug this program, and exit from main i get an error
Run-Time Check Failure #2 - Stack around the variable 'szString' was corrupted.
what i am doing wrong ?
What I have tried:
instead of allocating szString on stack, i tried it with heap,
like
void main ()
{
WCHAR * szString = new WCHAR [MAX_NAME_LENGTH] ;
wcscpy_s(szString, MAX_NAME_LENGTH, L"This is Some String");
printf ("Before Call String Value=[%s]", szString);
ModifyString2(szString);
printf ("Before Call String Value=[%s]", szString);
delete szString;
return 0;
}
This may be due to a corruption of the heap, which indicates a bug in MFCClient.exe or any of the DLLs it has loaded.
Not sure, what i am doing wrong, I am using Visual Studio 2010 ultimate, on a windows box.
please Help.
-praveen.