堆的损坏
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef int Elemtype;
typedef struct{
Elemtype *base[2];
Elemtype *top[2];
}BDStacktype; //双向栈类型
int Init_Stack(BDStacktype &tws,int m)//初始化一个大小为m的双向栈tws
{
tws.base[0]=(Elemtype*)malloc(sizeof(Elemtype));
tws.base[1]=tws.base[0] + m;
tws.top[0]=tws.base[0];
tws.top[1]=tws.base[1];
return OK;
}//Init_Stack
int push(BDStacktype &tws,int i,Elemtype x)//x入栈,i=0表示低端栈,i=1表示高端栈
{
if(tws.top[0]>tws.top[1]) return OVERFLOW;
if(i==0) *tws.top[0]++=x;
else if(i==1) *tws.top[1]--=x;
else return ERROR;
return OK;
}//push
int pop(BDStacktype &tws,int i,Elemtype &x)//x出栈,i=0表示低端栈,i=1表示高端栈
{
if(i==0)
{
if(tws.top[0]==tws.base[0]) return OVERFLOW;
x=*--tws.top[0];
// free(tws.top[0]+1);
}
else if(i==1)
{
if(tws.top[1]==tws.base[1]) return OVERFLOW;
x=*++tws.top[1];
// free(tws.top[1]);
}
else return ERROR;
return OK;
}//pop
void main()
{
Elemtype e;
BDStacktype tws;
Init_Stack(tws,6);
// printf("输入栈中元素");//i=0为低端,i=1为高端。
push(tws, 0, 1);
push(tws, 0, 2);
push(tws, 0, 3);
push(tws, 1, 6);
push(tws, 1, 5);
push(tws, 1, 4);
printf("输出元素:");
pop(tws,0,e);
printf("%d ", e);
pop(tws,0,e);
printf("%d ", e);
pop(tws,0,e);
printf("%d ", e);
pop(tws,1,e);
printf("%d ", e);
pop(tws,1,e);
printf("%d ", e);
pop(tws,1,e);
printf("%d ", e);
printf("\n");
// getchar();
system("PAUSE");
}
Critical error detected c0000374
Windows 已在 test.exe 中触发一个断点。
其原因可能是堆被损坏,这说明 test.exe 中或它所加载的任何 DLL 中有 Bug。
原因也可能是用户在 test.exe 具有焦点时按下了 F12。
输出窗口可能提供了更多诊断信息。
(VC运行完全OK。。。)
...全文
相关推荐
cpp-libdheap一个共享动态库可以透明地注入到不同的进程中以检测glibc堆中的内存损坏
libdheap一个共享(动态)库,可以透明地注入到不同的进程中,以检测glibc堆中的内存损坏
8、识别堆区域和堆损坏的实践指南
本文详细介绍了如何使用 GDB 和 WinDbg Preview 调试工具识别堆区域和堆损坏问题,重点分析了内存错误的定位与解决方法。通过实际案例,展示了从加载文件、设置日志到检查内存地址和堆栈跟踪的完整调试流程,同时探讨了常见的内存问题如“释放后写入”的成因及应对策略。文章旨在帮助开发者提升调试技能,增强程序的稳定性和可靠性。
整流桥堆四脚怎么测量好坏
想知道四脚整流桥好坏判断的方法,你首先得了解实际操作接线上机测试的方法!ASEMI实际操作一步到位!
Win32堆调试支持[源码]
本文详细介绍了Win32堆的调试支持功能,包括堆尾检查(HTC)、释放检查(HFC)、参数检查、调用时验证(HVC)、堆块标记、用户态栈回溯(UST)以及专门用于调试的页堆(DHP)。文章重点讲解了页堆的工作原理及其在调试中的优势,如通过栅栏页实时检测堆溢出问题。此外,还介绍了如何使用gflags.exe工具开启和配置这些调试选项,并通过实际代码示例展示了页堆在调试中的效果。最后,文章简要提及了准页堆的概念及其适用场景,强调了页堆在解决复杂堆破坏问题中的重要性。
Debugging Heap Corruption in Visual C++
Debugging Heap Corruption in Visual C++ Using Microsoft Debugging Tools for Windows


新手乐园
