VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法
问题
:
在用VS2008写一段代码,算法都没有问题,但是调试的时候发现出了main之后就报 Stack around the variable 'xxx' was corrupted 的错误,后来发现是数组越界造成的。测试下面类似情形的代码:
- #include <iostream>
- using namespace std;
- int main()
- {
- int i, j, tmp;
- int a[10] = {0};// 0, 1, ... , 9
- for(i = 0; i < 10; ++i)
- {
- a[i] = 9 - i;
- }
- for(j=0; j<=9; j++)
- {
- for (i=0; i<10-j; i++)
- {
- if (a[i] > a[i+1])// 当j == 0时,i会取到,导致a[i+1]越界
- {
- tmp = a[i];
- a[i] = a[i+1];
- a[i+1] = tmp;
- }
- }
- }
- for(i=1;i<11;i++)
- {
- cout << a[i]<<endl;
- }
- system("pause");
- return 0;
- }
出现下图 Debug Error:
Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted

原因
:
Stack pointer corruption is caused writing outside the allocated buffer in stack memory.
解决方法
:
This kind of error is detected by setting /RTC1 compiler option from menu 属性页(Alt+F7) -> 配置属性 -> C++ -> 代码生成 -> 基本运行时检查
有以下几个选项:
(1) 默认值
(2) 堆栈帧 ( /RTCs )
(3) 未初始化的变量 ( /RTCsu )
(4) 两者 ( /RTC1, 等同与 /RTCsu )
(5) <从父级或项目默认设置继承>
方法1 :修改数组越界的错误。
方法2 :设置为 (1) 默认值,就不再进行 stack frame run-time error checking。
Using /RTC1 compiler option 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;
- }
参考 :
Stack around the variable was corrupted 解决方案
http://laokaddk.blog.51cto.com/368606/238718
stack around the variable was corrupted
http://www.cnblogs.com/hxf829/archive/2009/11/28/1659749.html
VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法的更多相关文章
- Run-Time Check Failure #2 Stack around the variable ‘xxx’ was corrupted
在改别人代码时,运行报错: Run-Time Check Failure #2 Stack around the variable 'buffer' was corrupted 这表明你对某变量的赋值 ...
- c++. Run-Time Check Failure #2 - Stack around the variable 'cc' was corrupted.
Run-Time Check Failure #2 - Stack around the variable 'cc' was corrupted. char cc[1024]; //此处如果索引值 ...
- Run-Time Check Failure #2 - Stack around the variable 's' was corrupted. 出现了 。
程序中存在内存越界,注意数组大小和数据大小.
- vs中 Stack around the variable 'XXX' was corrupted.
https://blog.csdn.net/hou09tian/article/details/75042206 把 project->配置属性->c/c++->代码生成->基 ...
- Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt
Run-Time Check Failure #2 一般是栈被破坏,你的代码可能有缓冲区溢出一类的问题. Run-Time Check Failure #2 - Sta ...
- Stack around the variable 'szStr' was corrupted.
错误:stack around the variable “XX” was corrupted.,中文翻译就是“在变量XX周围的堆栈已损坏”. 把 project->配置属性->c/c++ ...
- macOS 中使用 phpize 动态添加 PHP 扩展的错误解决方法
使用 phpize 动态添加 PHP 扩展是开发中经常需要做的事情,但是在 macOS 中,首次使用该功能必然会碰到一些错误,本文列出了这些错误的解决方法. 问题一: 执行 phpize 报错如下: ...
- WPF:指定的命名连接在配置中找不到、非计划用于 EntityClient 提供程序或者无效的解决方法
文/嶽永鹏 WPF 数据绑定中绑定到ENTITY,如果把数据文件做成一个类库,在UI文件中去应用它,可能遇到下面这种情况. 指定的命名连接在配置中找不到.非计划用于 EntityClient 提供程序 ...
- zend studio中ctrl+鼠标左键无法转到类或函数定义文件的解决方法
转载自:http://blog.csdn.net/wide288/article/details/21622183 zend studio中ctrl+鼠标左键无法转到类或函数定义文件的解决方法: ze ...
随机推荐
- xrange()与range()
range(start,stop,step) range(0,8) >>print range(0,8) [0,1,2,3,4,5,6,7] range()返回一个数字列表. start ...
- css中position中的几个属性
static 是默认值.任意 position: static; 的元素不会被特殊的定位.一个 static 元素表示它不会被"positioned",一个 position 属 ...
- java练习 - 字符串反转
思路: 1. 首先将字符串转换成数组,一个数组元素放一个字符. 2. 循环遍历字符串,将所有字符串前后字符调换位置,比如:第一个和最后一个调换,第二个和倒数第三调换,第三个和倒数第三调换,直到所有字符 ...
- WEB 技术分类 Javascript DOM(Element Node) BOM
Web technology for developers Web 技术文档 备注:本文介绍web technology的分类,各自职责,因为之前一直就没有搞明白各种技术.各种名词究竟是属于哪个范 ...
- VB VBA VBS有什么区别?
VB和VBA本就是同宗的姐妹,只不过姐姐VB的功夫要比妹妹VBA历害些.不过姐姐只会单打独斗是女强人:妹妹却只会傍大款(例如Office).姐姐有生育能力,是真正的女人:妹妹却不会生崽(生成.EXE) ...
- RF+Jenkins构建持续集成
引入RF是为了能够快速的开展自动化验收测试,Jenkins而一种持续集成工具,用于监控持续重复的工作,持续的软件版本发布/测试项目,而通过RF+Jenkins可以有利的对RF构建的接口项目进行持续集成 ...
- 第八十六节,html5+css3pc端固定布局,网站结构,CSS选择器,完成导航
html5+css3pc端固定布局,网站结构,CSS选择器,完成导航 页面采用1280的最低宽度设计,去掉滚动条为1263像素. 项目是PC端的固定布局,会采用像素(px)单位. 网站结构语义 在没有 ...
- HTML5 中的新特性:
一,用于绘画的 canvas 元素,<canvas>标签替代Flash Flash给很多Web开发者带来了麻烦,要在网页上播放Flash需要一堆代码和插件.<canvas>标签 ...
- java中三大修饰符
一.static 1.属性:类变量 定义在类以内,方法以外,全类有效,全类公共一个属性 类变量与创建对象无关,有默认值0 使用方式 类名.类变量 System.out.println(); ...
- 【Sort】RadixSort基数排序
太晚了,明天有时间在写算法思路,先贴代码 ------------------------------------------------ 刚答辩完,毕业好难,感觉自己好水 ------------- ...