I am coding a C++ win32 app and encounter a weird appearance which is that access violation instruction will not always cause app crashed, It depends where the instruction inserted! Here is the case I encountered : I have used a third party library, and If I put *(int *0)=0; in one special overload function of that library, The program will not crash and some instruction will be skipped which result that the program run in a abnormal status. code like the below:
void CMainWnd::InitWindow(){
//other constructions
(*(int *)0) = 0;//access violation
//other construction which is under *(int *0)=0; in InitWindow scope will not be executed.
//.....
}
I guess the library have used some SEH Technology, so search through the library codebase and not found any relative API used.
SO, WHAT HAPPENED???
----- split line ----------
Thanks everyone's response, after Daniel Sęk`s prompt. I add more detail to here. Here is crash function call stack.
duidemo_d.exe!crash() Line 73 C++
duidemo_d.exe!CMainWnd::InitWindow() Line 89 C++
DuiLib_d.dll!DuiLib::WindowImplBase::OnCreate(unsigned int uMsg, unsigned int wParam, long lParam, int & bHandled) Line 313 C++
DuiLib_d.dll!DuiLib::WindowImplBase::HandleMessage(unsigned int uMsg, unsigned int wParam, long lParam) Line 359 C++
DuiLib_d.dll!DuiLib::CWindowWnd::__WndProc(HWND__ * hWnd, unsigned int uMsg, unsigned int wParam, long lParam) Line 436 C++
here is how DuiLib_d.dll!DuiLib::CWindowWnd::__WndProc is invoked.Registers a window class which has WNDCLASS::lpfnWndProc=CWindowWnd::__WndProc for subsequent use in calls to the CreateWindow or CreateWindowEx function.
------split line-----
The reason for why I do this test is that I want to catch every unexpected thing happens in my program and dump it ,debug it ,figure out how it happened and solve it, finally reduce one bug. It seems that my catch method does not work well if exception happened in wndproc whatsoever exceotion code is. Here is the method how I create dump file.SetUnhandledExceptionFilter is called after WinMain.
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CallBackCrashHandler);
//dump
LONG CallBackCrashHandler(EXCEPTION_POINTERS* pException)
{
//write dump
HANDLE hFile = CreateFile(gBugReport->m_dumpFilePath.data(), GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
MINIDUMP_EXCEPTION_INFORMATION l_eInfo;
l_eInfo.ThreadId = GetCurrentThreadId();
l_eInfo.ExceptionPointers = pException;
l_eInfo.ClientPointers = FALSE;
MiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
hFile,
MiniDumpNormal,
pException ? &l_eInfo : NULL,
NULL,
NULL);
CloseHandle(hFile);
return EXCEPTION_EXECUTE_HANDLER;
}