我在完成老师布置的课程设计时遇到了这样的错误:stack around the variable “XX” was corrupted.,中文翻译就是“在变量XX周围的堆栈已损坏”。后面在上网看了很多技术资料,发现大多数网站都有这样的文章:

Code:
  1. 把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值 就不会报本异常。具体原因正在研究中。。。
  2. 如果改为其他就有exception。
  3. exception有时是有道理的
  4. // step 1
  5. STRINGC2& STRINGC2::operator += (const char x)
  6. {
  7. // if (x == 0) return *this;
  8. char ptr[1]; // max is 1 digit
  9. ptr[0] = x;
  10. ptr[1] = '/0';
  11. *this += ptr; // off to step 2 and back
  12. return *this; // step 4 crash
  13. }
  14. 这个也会导致上述exception。
  15. 问题描述:
  16. Problem
  17. The following error message occurs when building on Test RealTIme environment with the cvisual7 TDP?
  18. Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted.
  19. Cause
  20. Stack pointer corruption is caused writing outside the allocated buffer in stack memeory.
  21. Solution
  22. 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.
  23. #include <stdio.h>
  24. #include <string.h>
  25. #define BUFF_LEN 11 // 12 may fix the Run-Time Check Failure #2
  26. int rtc_option_test(char * pStr);
  27. int main()
  28. {
  29. char * myStr = "hello world";
  30. rtc_option_test(myStr);
  31. return 0;
  32. }
  33. int rtc_option_test(char * pStr)
  34. {
  35. char buff[BUFF_LEN];
  36. strcpy(buff, pStr); //cause Run-Time Check Failure #2 - Stack around
  37. //the variable 'buff' was corrupted.
  38. return 0;
  39. }

我也尝试了把“project->配置属性->c/c++->代码生成”改为基本运行时检查,就没有这样的错误了。关于MSDN的解释是在堆栈外面读写某数据。错误是名为RTC1的编译器检测的。又看了更多的技术文章,发现这样的错误是程序员在项目到了一定大的时候,它占用的堆栈量就比较大。我也深有体会。因为自己本来编写一个类,运行时没有错,但是在添加成员属性的时候,在其它方式不变的情况下就容易发生这样的错误。所以据此我猜应该是VS2005(2008)在内部就限定了堆栈的大小,当项目足够大的时候,就会溢出。

浅析stack around the variable was corrupted(含转的文章)相关推荐

  1. VS中stack around the variable ‘****‘ was corrupted堆栈被破坏

    有时候VS中报stack around the variable '****' was corrupted堆栈被破坏错误,如果治标不治本的方法,可以将如下修改为:默认值 最根本的办法就是找到哪里超出了 ...

  2. stack around the variable “” was corrupted

    在写一个很简单的程序的时候,出现stack around the variable "" was corrupted的错误,检查程序本身没有问题 程序如下 #include < ...

  3. c++ stack around the variable “ “ was corrupted

    很久没玩c++,快忘了 出现这个错误,是数组长度不够 string aa;char s[1] = {0}; // char s[4] = {0} 后正常for (int i = 0; i < 2 ...

  4. 【C语言学习疑难杂症】Stack arround the variable was corrupted问题

    提出问题: 在开启正文之前,我们先看这样一个例子. 我们重点看这个弹出的Debug Errir框,中间划红线的部分,它报了这样一个错误. 首先,我们特别强调一个问题就是,这个问题可能会在很多同学以后的 ...

  5. 解决 stack around the variable was corrupted 问题

    在我建立一个包含学生信息的文本文件,并向文件输出数据时,出现了堆栈问题.源码如下: #include "stdafx.h" #include <iostream> #i ...

  6. Run-Time Check Failure #2 Stack around the variable ‘xxx’ was corrupted

    在改别人代码时,运行报错: Run-Time Check Failure #2 Stack around the variable 'buffer' was corrupted 这表明你对某变量的赋值 ...

  7. 有关Run-Time Check Failure #2 - Stack around the variable 'XXX' was corrupted.错误的解决方法

    有关Run-Time Check Failure #2 - Stack around the variable 'XXX' was corrupted.错误的解决方法 今天我在敲完一段代码运行的时候出 ...

  8. 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越界 ...

  9. 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调代码的时候,会出现这个问题,经过查找以及 ...

最新文章

  1. mysql 查询不使用索引_简单的mySQL查询不使用索引
  2. ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件...
  3. OpenCV2.3的cvCalcHist函数有问题?255级值总为0,索性自己写一个直方图计算函数,附源码
  4. DevOps简单介绍
  5. mysql字符集排序规则_Mysql 字符集及排序规则
  6. gcc交叉编译的实现
  7. PTA-数组元素循环右移问题
  8. 嵩天python123测试6_神华化工股票
  9. 欧洲英语语言c1证书,威尼斯大学认可的英语语言证书
  10. 细说OSI七层协议模型及OSI参考模型中的数据封装过程?
  11. atitit。gui 界面皮肤以及换肤总结 java .net c++
  12. 微信小程序支付宝小程序合并二维码
  13. 2013Esri全球用户大会QA之Web GIS
  14. JAVA封装,继承,多态详解
  15. 关于图片的Exif信息
  16. matlab中单刀双掷开关,单刀双掷开关与双刀双掷开关的区别
  17. SNN识别手写数字—MNIST数据集
  18. 求导四则运算以及三角函数求导 Derivative formulas
  19. 专访 iOS 技术专家孙源:开发者的成长始于“死磕”
  20. python中import文件夹下面py文件,报错

热门文章

  1. IDA安装keypatch插件
  2. C++STL库常用库函数总结
  3. C语言---会思考的三子棋
  4. 记录一次逆向并自己编写游戏mod
  5. 本地使用IIS快速搭建一个属于自己的网站,并发布公网访问「无需购买云服务器」
  6. 使用python加PyQt5,利用QMediaPlayer写一个简易的音乐播放器(进度条拖动,音量改变,播放停止切换,歌曲列表))
  7. 来一场轰轰烈烈的HTTP协议扫盲革命
  8. 从零开始构建PHP版mud游戏(三)
  9. lol提示游戏环境异常重启计算机,lol游戏环境异常请重启机器该怎么办
  10. 给公司小伙伴培训的 Kafka等MQ 入门知识,了解一下?