vc++中debug error: Damage before/after normal block

在程序运行结束时,VC++ 6.0如果出现这样一个对话框

关于debug <wbr>error:Damage <wbr>before <wbr>normal <wbr>block

就是触发了debug error: Damage before/after normal block

       如果编译器报这样的错,几乎可以肯定是在程序中,数组访问越界。例如:

int main()

{

       int *p=new int[5];

       p[-1]=3;

       delete [] p;

       return 0;

}

当执行至delete 语句时,就会弹出上图那个对话框,报damage before normal block

如果程序修改成这样

int main()

{

       int *p=new int[5];

       p[5]=3;

       delete [] p;

       return 0;

}

执行至delete语句时,则会报damage after normal block 的错误。

       什么是normal block?在使用new 操作符为指针申请内存空间时,VC编译器为该指针分配的内存空间就是normal block。这段内存空间每个字节的初始值均为 CD h 。并且把该段内存空间之前4个字节和之后4个字节

的初值赋值为FDFDFDFD h。

       用VC的Memory工具可以方便地查看到这段新分配的内存空间的内容。如上面的两个程序,VC为指针p申请的内存空间地址从0x00032f48起始。用Memory查看这个地址附近的内容,就是下图显示的内容:

关于debug <wbr>error:Damage <wbr>before <wbr>normal <wbr>block

       在用delete 释放该段内存空间时,编译器会检查该段内存之前4个字节内容和之后4个字节内容是否有被改动。如果有,则分别报damage before normal block和damage after normal block。

       但是,VC编译器的这种检错功能是十分有限的,防止数组访问越界,主要靠程序员自己小心。如上面的

程序中,如果让p[-2]=3,即对内存地址0x00032F44之前的内存进行改动,编译器是检测不出这样的错误的。同理,对p[6]赋值,或者将p[5]=0xFDFDFDFD,编译器都不会报错的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenSSH_9.2p1 Debian-2, OpenSSL 3.0.9 30 May 2023 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to lxslc702.ihep.ac.cn [2401:de00:2:332::186] port 22. debug1: Connection established. debug1: identity file /home/fyf/.ssh/id_rsa type -1 debug1: identity file /home/fyf/.ssh/id_rsa-cert type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa_sk type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /home/fyf/.ssh/id_ed25519 type -1 debug1: identity file /home/fyf/.ssh/id_ed25519-cert type -1 debug1: identity file /home/fyf/.ssh/id_ed25519_sk type -1 debug1: identity file /home/fyf/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /home/fyf/.ssh/id_xmss type -1 debug1: identity file /home/fyf/.ssh/id_xmss-cert type -1 debug1: identity file /home/fyf/.ssh/id_dsa type -1 debug1: identity file /home/fyf/.ssh/id_dsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006 debug1: Authenticating to lxslc702.ihep.ac.cn:22 as 'fanyufan' debug1: load_hostkeys: fopen /home/fyf/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /home/fyf/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ssh-ed25519 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY Connection closed by 2401:de00:2:332::186 port 22
最新发布
07-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值