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 ...
随机推荐
- CNN计算过程
- freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建
今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...
- 两个队列实现一个栈,剑指offer P59
public class StackByQueue { private LinkedList<String> queue1; private LinkedList<String> ...
- MyBatis中update的使用
当你传入所需要修改的值为一个实体对象时,可能只改动了其中部分的值.那么其他值需要做一个判断是否为空值的操作. XXXmapper.xml <update id="updateMembe ...
- C# 常用接口学习 IComparable 和 IComparer
C# 常用接口学习 IComparable 和 IComparer 作者:乌龙哈里 时间:2015-11-01 平台:Window7 64bit,Visual Studio Community 201 ...
- iframe标签使用总结与注意问题
子页面访问父父页面变量,函数,页面元素 //变量: //在父页面中需定义为全局变量 //子页面中调用 var childFrameVar= parent.ParentVarName; //函数: pa ...
- fopen()函数以"a+"方式打开一个不存在的文件后读写出现问题
问题:在完成课后习题的时候,使用fopen()函数以"a+"方式打开一个不存在的文件时,写入.读取出现错误: //添加用户输入单词后,在单词头加入编号,确保编号跟着前面的开始排序 ...
- JS跨域访问问题
js跨域了. 只能给几个资料参考了:http://blog.csdn.net/lovingprince/article/details/2954675 http://www.kuqin.com/web ...
- 《JS权威指南学习总结--8.8.4 记忆函数》
内容要点: 可以将上次的计算结果缓存起来.在函数式编程当中,这中缓存技巧叫做 "记忆". 需要注意的是,记忆只是一种编程技巧,本质上是牺牲算法的空间复杂度以换取更优的时间复杂度 ...
- PAT 团体程序设计天梯赛-练习集 L1-017. 到底有多二
一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值.如果这个数是负数,则程度增加0.5倍:如果还是个偶数,则再增加1倍.例如数字“-13142223336”是个11位数,其中有3个2,并且 ...