stack around the variable “XX” was corrupted
晚上花了几个小时fix了这个恼人的BUG!“在变量XX周围的堆栈已损坏”
在网上找到的解释是:
把“project->配置属性->c/c++->代码生成->基本运行时检查 设置为默认值,就没有这样的错误了。关于MSDN的解释是在堆栈外面读写某数据。错误是名为RTC1的编译器检测的。又看了更多的技术文章,发现这样的错误是程序员在项目到了一定大的时候,它占用的堆栈量就比较大。我也深有体会。因为自己本来编写一个类,运行时没有错,但是在添加成员属性的时候,在其它方式不变的情况下就容易发生这样的错误。所以据此我猜应该是VS在内部就限定了堆栈的大小,当项目足够大的时候,就会溢出。
char *transformation(char *str) //在字符串插入字符的个数,如"aaabb" 转换后为 aaa3bb2
{
if (NULL == str)
{
return NULL;
}
char *temp =str;
int len =strlen(str);
int count = ;
char* buf = new char[len+];
char* pos =str;
char* pos1 = str+;
while (*str)
{
if (*pos++ == *pos1++)
{
count++;
}
else
{
int2str(count,buf); //本来开始准备用_itoa_s发现不好用,自己写了一个整形转字符串函数
int nbit = strlen(buf);
strcat_s(buf,len+,pos);
*pos=;
strcat_s(str,*len,buf);
pos +=nbit;
pos1+=nbit;
str = pos;
count =;
}
}
delete []buf;
return temp; }
我在函数栈内申请了一个buf的字符数组,最开始我设置数组长度为200出现了BUG,设置为len+1后没报BUG,可能就是因为堆栈占用过多。
还有想吐槽一下 C++里的 strcat_s(),_itoa_s()函数用起来很不爽,还要指定长度,虽然这样可以防止溢出,但是我觉得用起来不爽,为什么_strcat_s()不在函数里面调用strlen()检查,还要程序员自己指定,不如C里面的strcat()好用
stack around the variable “XX” was corrupted的更多相关文章
- Stack around the variable 'szStr' was corrupted.
错误:stack around the variable “XX” was corrupted.,中文翻译就是“在变量XX周围的堆栈已损坏”. 把 project->配置属性->c/c++ ...
- VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法
问题 : 在用VS2008写一段代码,算法都没有问题,但是调试的时候发现出了main之后就报 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 这表明你对某变量的赋值 ...
- vs中 Stack around the variable 'XXX' was corrupted.
https://blog.csdn.net/hou09tian/article/details/75042206 把 project->配置属性->c/c++->代码生成->基 ...
- 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 was corrupted”的解决方案
把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值 就不会报本异常.具体原因正在研究中... 如果改为其他就有exception. exce ...
- 运行时错误:“stack around the variable…was corrupted”
造冰箱的大熊猫@cnblogs 2018/11/1 引发问题的代码片段如下 WORD var; scanf ( "%d", &var ); 包含上述代码的程序,编译正常,运 ...
- Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt
Run-Time Check Failure #2 一般是栈被破坏,你的代码可能有缓冲区溢出一类的问题. Run-Time Check Failure #2 - Sta ...
随机推荐
- ubuntu下安装opencv 2.4.9 脚本,支持摄像头和cuda
arch=$(uname -m) if [ "$arch" == "i686" -o "$arch" == "i386" ...
- HW5.7
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 全英文版时间格式化07/29/2010 4:14:01 PM
之前格式化,AM PM出不来,总是显示上午 下午 aspx页面的绑定: <%#Eval("AddDate") == DBNull.Value ? "" : ...
- eclipse老是卡在Refreshing workspace
最近老是遇到eclipse没有响应,参考网络上的相关帖子做了些优化,但问题依旧. 后来发现出现这个问题一般都是eclipse无响应,直接结束进程后导致的,看了下eclipse日志,果真如此. !SES ...
- JS 单元测试
JS单元测试,我工作时主要以mocha + chai 下面时具体的文档: mocha: https://mochajs.org/#asynchronous-code Chai: http://chai ...
- css Spirtes 错位问题解决
本文为转载内容,原文链接: https://github.com/banricho/webLog/issues/1
- oracle并行模式(Parallel)
1. 用途 强行启用并行度来执行当前SQL.这个在Oracle 9i之后的版本可以使用,之前的版本现在没有环境进行测试.也就是说,加上这个说明,可以强行启用Oracle的多线程处理功能.举例的话,就 ...
- leecode 每日解题思路 152 Maximun Product Subarray
问题描述: 问题链接:152 Maximum Product Subarray 在经典的算法解析中, 有关的分治和动态规划的,经典题型之一就是求最大子段和, 这道题就是他的变形:求最大子段积; 这个问 ...
- [转]VS2010 (C#)winform程序打包发布图解
1.新建一个Windows窗体应用程序,例如项目名为monitor,功能略.新建的时候不要忘了创建解决方案. 2.在monitor解决方案上“右击”—— “添加”——“新建项目”,选择“其他类型项目” ...
- oracle表锁住 解锁办法
第一种方法: 用系统账户如sys as SYSDBA 登录进去 1.查看数据库锁,诊断锁的来源及类型: select object_id,session_id,locked_mode f ...