#include int main() { char szBuff[1]; for(char *pBuff = szBuff;;pBuff++) *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }
when run in a debugger gives the following error: Unhandled exception in test1.exe: 0xC0000005: Access Violation But does not display any sort of exception when run outside a debugger and crash directly.
The system depends on information saved on the stack to unwind exceptions; as the whole stack is trashed in this case, attempting to call the default handler (which would display the error message box, and optionally attach a debugger) will only result in a new exception, upon which the program will be terminated immediately.
Under a debugger however, the system will suspend the program and notify the debugger, giving it a chance to deal with the problem first.
#include int main() { char szBuff[1]; for(char *pBuff = szBuff+1024;;pBuff++) // added the +1024 *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }
and I got these 2 errors... The instruction at "0x0040b4cf" referenced memory at "0x00133000". The memory could not be written && The instruction at "0x77f84abe" referenced memory at "0x24242430". The memory could not be read That little jump ahead saved part of the stack !
Top 13 楼baobao(天下草木皆能当剑) 回复于 2002-02-05 09:24:21 得分 0
to masterz(): 你给出的第一个例子确实捕获不到,非常感谢! 可是我如何在茫茫的代码中找到那条出错的语句。 有什么快捷的调试方法?望赐教。 Top 14 楼sohohome(三层肚皮) 回复于 2002-02-05 10:46:12 得分 0
怎样捕获#include int main() { char szBuff[1]; for(char *pBuff = szBuff;;pBuff++) *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }
的异常?0xC0000005无法捕获吗? Top 15 楼baobao(天下草木皆能当剑) 回复于 2002-02-06 13:46:44 得分 0
请问大家是否遇到过这样的问题,如何调试? Top 16 楼riflek() 回复于 2002-02-06 14:07:37 得分 0
我在编写服务器程序的时候也出现这种情况过,我也是用学日志的形式来调试,没什么反映的就退出了。后来一次偶然的机会发现一个内存溢出的错误修改后就没有再出现突然退出的情况。我也说不出什么原因,windows核心中好像有说过,当内存溢出时会访问一个专门的区域,从而引发访问违规,系统不进行提示的,程序就退出了。 Top 17 楼lownr(廖宇雷) 回复于 2002-02-06 23:25:08 得分 0