首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

怎么扑捉:该内存不能为"written" 的异常

2012-02-17 
如何扑捉:该内存不能为written 的错误?下面代码运行过程出现:0x0040132c指令引用的0x0012004a内存。

如何扑捉:该内存不能为"written" 的错误?
下面代码运行过程出现:"0x0040132c"指令引用的"0x0012004a"内存。该内存不能为"written"
原因是test数组最多只能存储3个字符;请问如何扑捉这个错误?

C/C++ code
#include <stdio.h>#include <stdlib.h>void main(int argc, char *argv[]){    char test[3]={0};    sprintf(test,"abcdef");    printf(test);}


[解决办法]
类似的越界的问题原则上是未雨绸缪而不是亡羊补牢的~~~
[解决办法]
探讨

引用:
类似的越界的问题原则上是未雨绸缪而不是亡羊补牢的~~~

楼上说的在理。。。
引用:
C/C++ code

#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
char test[3]={0};
sprintf……

[解决办法]
To set a breakpoint when a variable "test[3]" changes value 
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the name of the variable "test[3]".
Click OK to set the breakpoint. 

[解决办法]
__try
{
// faulty code here.
}
__except (// exception filters here.)
{
// exception handling code here.
}
__finally
{
// cleaning code here.
}
[解决办法]
探讨

引用:

修改之后;为什么没有输出__except?
C/C++ code

#include <stdio.h>

void main(int argc, char *argv[])
{
char test[3]={0};
__try
{
sprintf(test,"abcdef");
}
__except(1)
{
put……
……

[解决办法]
要截获内存访问违例得改操作系统内核代码,内核存储管理代码在检测到读写非法线性地址的时候崩的错误,这类错误没办法恢复的,连操作系统都不知道如果恢复的话给应用程序怎么一个状态,全乱套了~
[解决办法]
探讨

修改之后;为什么没有输出__except?
C/C++ code

#include <stdio.h>

void main(int argc, char *argv[])
{
char test[3]={0};
__try
{
sprintf(test,"abcdef");
}
__except(1)
{
put……

[解决办法]
探讨
判断跨界的时候 realloc一下你的数组 然后再放进去

热点排行