浅析stack around the variable was corrupted(含转的文章)
我在完成老师布置的课程设计时遇到了这样的错误:stack around the variable “XX” was corrupted.,中文翻译就是“在变量XX周围的堆栈已损坏”。后面在上网看了很多技术资料,发现大多数网站都有这样的文章:
- 把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值 就不会报本异常。具体原因正在研究中。。。
- 如果改为其他就有exception。
- exception有时是有道理的
- // step 1
- STRINGC2& STRINGC2::operator += (const char x)
- {
- // if (x == 0) return *this;
- char ptr[1]; // max is 1 digit
- ptr[0] = x;
- ptr[1] = '/0';
- *this += ptr; // off to step 2 and back
- return *this; // step 4 crash
- }
- 这个也会导致上述exception。
- 问题描述:
- Problem
- The following error message occurs when building on Test RealTIme environment with the cvisual7 TDP?
- Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted.
- Cause
- Stack pointer corruption is caused writing outside the allocated buffer in stack memeory.
- Solution
- This kind of error is detected by setting /RTC1 compiler option from menu Project -> Settings -> Configuration properties -> Build -> Compiler -> Compiler flags when using TDP cvisual7 in IBM® Rational® Test RealTime environment.. This enables stack frame run-time error checking. For example, the following code may cause the above error messge.
- #include <stdio.h>
- #include <string.h>
- #define BUFF_LEN 11 // 12 may fix the Run-Time Check Failure #2
- int rtc_option_test(char * pStr);
- int main()
- {
- char * myStr = "hello world";
- rtc_option_test(myStr);
- return 0;
- }
- int rtc_option_test(char * pStr)
- {
- char buff[BUFF_LEN];
- strcpy(buff, pStr); //cause Run-Time Check Failure #2 - Stack around
- //the variable 'buff' was corrupted.
- return 0;
- }
我也尝试了把“project->配置属性->c/c++->代码生成”改为基本运行时检查,就没有这样的错误了。关于MSDN的解释是在堆栈外面读写某数据。错误是名为RTC1的编译器检测的。又看了更多的技术文章,发现这样的错误是程序员在项目到了一定大的时候,它占用的堆栈量就比较大。我也深有体会。因为自己本来编写一个类,运行时没有错,但是在添加成员属性的时候,在其它方式不变的情况下就容易发生这样的错误。所以据此我猜应该是VS2005(2008)在内部就限定了堆栈的大小,当项目足够大的时候,就会溢出。
浅析stack around the variable was corrupted(含转的文章)相关推荐
- VS中stack around the variable ‘****‘ was corrupted堆栈被破坏
有时候VS中报stack around the variable '****' was corrupted堆栈被破坏错误,如果治标不治本的方法,可以将如下修改为:默认值 最根本的办法就是找到哪里超出了 ...
- stack around the variable “” was corrupted
在写一个很简单的程序的时候,出现stack around the variable "" was corrupted的错误,检查程序本身没有问题 程序如下 #include < ...
- c++ stack around the variable “ “ was corrupted
很久没玩c++,快忘了 出现这个错误,是数组长度不够 string aa;char s[1] = {0}; // char s[4] = {0} 后正常for (int i = 0; i < 2 ...
- 【C语言学习疑难杂症】Stack arround the variable was corrupted问题
提出问题: 在开启正文之前,我们先看这样一个例子. 我们重点看这个弹出的Debug Errir框,中间划红线的部分,它报了这样一个错误. 首先,我们特别强调一个问题就是,这个问题可能会在很多同学以后的 ...
- 解决 stack around the variable was corrupted 问题
在我建立一个包含学生信息的文本文件,并向文件输出数据时,出现了堆栈问题.源码如下: #include "stdafx.h" #include <iostream> #i ...
- Run-Time Check Failure #2 Stack around the variable ‘xxx’ was corrupted
在改别人代码时,运行报错: Run-Time Check Failure #2 Stack around the variable 'buffer' was corrupted 这表明你对某变量的赋值 ...
- 有关Run-Time Check Failure #2 - Stack around the variable 'XXX' was corrupted.错误的解决方法
有关Run-Time Check Failure #2 - Stack around the variable 'XXX' was corrupted.错误的解决方法 今天我在敲完一段代码运行的时候出 ...
- C error :Run-Time Check Failure #2 - Stack around the variable 'b' was corrupted.
运行程序遇到这样的错误:Run-Time Check Failure #2 - Stack around the variable 'b' was corrupted. 检查后发现原因在于:数组b越界 ...
- Run-Time Check Failure #2 – Stack around the variable 'a' was corrupted.
Run-Time Check Failure #2 – Stack around the variable 'a' was corrupted. 今天在用VS调代码的时候,会出现这个问题,经过查找以及 ...
最新文章
- mysql 查询不使用索引_简单的mySQL查询不使用索引
- ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件...
- OpenCV2.3的cvCalcHist函数有问题?255级值总为0,索性自己写一个直方图计算函数,附源码
- DevOps简单介绍
- mysql字符集排序规则_Mysql 字符集及排序规则
- gcc交叉编译的实现
- PTA-数组元素循环右移问题
- 嵩天python123测试6_神华化工股票
- 欧洲英语语言c1证书,威尼斯大学认可的英语语言证书
- 细说OSI七层协议模型及OSI参考模型中的数据封装过程?
- atitit。gui 界面皮肤以及换肤总结 java .net c++
- 微信小程序支付宝小程序合并二维码
- 2013Esri全球用户大会QA之Web GIS
- JAVA封装,继承,多态详解
- 关于图片的Exif信息
- matlab中单刀双掷开关,单刀双掷开关与双刀双掷开关的区别
- SNN识别手写数字—MNIST数据集
- 求导四则运算以及三角函数求导 Derivative formulas
- 专访 iOS 技术专家孙源:开发者的成长始于“死磕”
- python中import文件夹下面py文件,报错