Click to See Complete Forum and Search --> : Run-Time Check Failure #2 - Stack around the variable was corrupted.


richmike3
January 10th, 2009, 02:13 AM
Hi All,

I have problem during execution of my program.
Error is Run-Time Check Failure #2 - Stack around the variable 'pwADErrBuff' was corrupted.
I increased variable pwADErrBuff size from 256 to 2048. But, still have problem.

Please help me in this,

Code Snippet is below,

WCHAR pwErrBuff[2048];
WCHAR pwADErrBuff[2048];
WCHAR * pADErrCodeStr;

pwErrBuff[0] = NULL;
pADErrCodeStr = CrackADError( passedhr);

int maxAlloc = sizeof(pwErrBuff)/sizeof(WCHAR);

// If an ADSI error code was returned, display it
if (pADErrCodeStr[0] != NULL)
{
SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> ADSI Error HRESULT Returns: <*> \n");
SAFE_APPEND(maxAlloc, pwErrBuff, pADErrCodeStr);
SAFE_APPEND(maxAlloc, pwErrBuff, L"\n");
}

// Call ADsGetLastError() to retrieve the error text from ADSI
SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> ADSI Error: <*>\n");

hr = ADsGetLastError(
&lError,
pwADErrBuff,
256,
L"",
0
);


if (FAILED(hr))
SAFE_APPEND(maxAlloc, pwErrBuff, L"<Unable to retrieve ADs Error>");
else
SAFE_APPEND(maxAlloc, pwErrBuff, pwADErrBuff);



SAFE_APPEND(maxAlloc, pwErrBuff, L"\n");

WCHAR sz[1024];

SAFE_APPEND(maxAlloc, pwErrBuff, L"<*> System Error: <*> \n");

// Check the standard system to crack the bad HRESULT into a string
if (!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 0, passedhr, 0, sz, 1024, 0))
wcscat(sz, L"Unknown HRESULT error");
else
SAFE_APPEND(maxAlloc, pwErrBuff, sz);


// Display
OutputDebugStringW(pwErrBuff);
OutputDebugStringW(L"\r\n");
_putws(L"\n**********");
wprintf(L"\nERROR on %s\n\n",pwReason);
_putws(pwErrBuff);
printf("\nERROR on %X\n\n",passedhr);
_putws(L"\n**********");

TheCPUWizard
January 10th, 2009, 02:20 AM
1) Please use code tags..go back and RE-READ the "BEfore you post" announcement if you have forgotten how.

2) The code does NOT look like (but it is hard to read without code tags!) C++/CLI [aka .NET] code. If it is NOT, then this is the WRONG forum, and need to ask a moderator to MOVE your thread (do NOT crate a duplicate, it simply creates more work for the moderator, who is already VOLUNTEERING (like the rest of us) his valuable time.