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 ...
随机推荐
- HW4.32
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW2.4
import java.util.Scanner; public class Solution { public static void main(String[] args) { final dou ...
- 查看Linux下*.a库文件中文件、函数、变量
查看Linux下*.a库文件中文件.函数.变量等情况在Linux 下经常需要链接一些 *.a的库文件,那怎么查看这些*.a 中包 含哪些文件.函数.变量: 1. 查看文件:ar -t xxx.a 2. ...
- 组件局域网中的无集线器、Windows XP、Windows 7、Windows 8的对等网
为什么要用对等网? 答:对等网采用分散管理的方式,网络中的每台计算机既作为客户机又可作为服务器来工作,每个用户都管理自己机器上的资源. 组建局域网中无集线器的对等网 组建局域网中Windows XP ...
- 编写高质量代码改善java程序的151个建议——导航开篇
2014-05-16 09:08 by Jeff Li 前言 系列文章:[传送门] 下个星期度过这几天的奋战,会抓紧java的进阶学习.听过一句话,大哥说过,你一个月前的代码去看下,慘不忍睹是吧.确实 ...
- J2EE之ServletContext读取资源文件
ServletContext读取资源文件内容的方式有两种: 方法1. public void doGet(HttpServletRequest request, HttpServletResponse ...
- 【转】Android 最火的快速开发框架XUtils
原文:http://blog.csdn.net/rain_butterfly/article/details/37812371 最近搜了一些框架供初学者学习,比较了一下XUtils是目前git上比较活 ...
- 导出项目为jar包
- 回击MLAA:NVIDIA FXAA抗锯齿性能实測、画质对照
PC游戏玩家肯定会对各式各样的AA抗锯齿技术很熟悉,而今天本文的主角就是NVIDIA今年才推出的新型抗锯齿技术"FXAA". FXAA在某种程度上有些类似于AMD之前宣传的MLAA ...
- Java生成word文档
itext-rtf-2.1.7.jar,下载地址:http://download.csdn.net/detail/xuxu198899223/7717727 itext-2.1.7.jar 下载地址: ...