应用程序崩溃的原因 [英] Application crash Reasons

查看:141
本文介绍了应用程序崩溃的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下代码导致崩溃?

Why is the following code leading to crash?

// <br />
// VC_CONSOLE.cpp : Defines the entry point for the console application. <br />
// <br />
#include "stdafx.h" <br />
#include "stdlib.h" <br />
#include "string.h" <br />
#include <stddef.h> <br />
#include <stdio.h> <br />
#include "io.h" <br />
#include <windows.h> <br />
#include <strsafe.h> <br />
#include <direct.h><br />
#include <conio.h><br />
<br />
void leaks()<br />
{<br />
    while(7)<br />
    {<br />
        char *a = (char*)malloc(28*sizeof(char));<br />
        {<br />
        strcpy(a,"cccccccc");<br />
        printf("%s\n",a);<br />
        }<br />
    }<br />
}<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
    leaks();<br />
    return 0;<br />
} <br />
</conio.h></direct.h></strsafe.h></windows.h></stdio.h></stddef.h>



调用堆栈为:



The call stack is:

0012fd68 0041365e MSVCR80D!strcat(unsigned char * dst = 0x00000000 "", unsigned char * src = 0x00000000 "")+0x89
0012fe5c 00411aea VC_CONSOLE!leaks(void)+0x7e
0012ff30 00411a06 VC_CONSOLE!wmain(int argc = 1, wchar_t ** argv = 0x051cef48)+0x3a
0012ff80 0041184d VC_CONSOLE!__tmainCRTStartup(void)+0x1a6
0012ff88 76da4911 VC_CONSOLE!wmainCRTStartup(void)+0xd
0012ff94 7737e4b6 KERNEL32!BaseThreadInitThunk+0xe
0012ffd4 7737e489 ntdll!__RtlUserThreadStart+0x23
0012ffec 00000000 ntdll!_RtlUserThreadStart+0x1b



我在windbg中遇到以下恐慌:



I am getting the following panic in windbg:

(1680.438): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=7efefefe ebx=7ffd7000 ecx=004157b0 edx=63636363 esi=0012fd78 edi=00000000
eip=676ef679 esp=0012fd68 ebp=0012fe5c iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246
MSVCR80D!strcat+0x89:
676ef679 8917            mov     dword ptr [edi],edx  ds:0023:00000000=????????

推荐答案

因为您要分配无限次(while(7))新的内存块(即有限资源).
Because you are allocating infinite times ( while(7) ) new chunks of memory (that is a finite resource).


这篇关于应用程序崩溃的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆