晚上花了几个小时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的更多相关文章

  1. Stack around the variable 'szStr' was corrupted.

    错误:stack around the variable “XX” was corrupted.,中文翻译就是“在变量XX周围的堆栈已损坏”. 把 project->配置属性->c/c++ ...

  2. VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法

    问题 : 在用VS2008写一段代码,算法都没有问题,但是调试的时候发现出了main之后就报 Stack around the variable 'xxx' was corrupted 的错误,后来发 ...

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

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

  4. vs中 Stack around the variable 'XXX' was corrupted.

    https://blog.csdn.net/hou09tian/article/details/75042206 把 project->配置属性->c/c++->代码生成->基 ...

  5. 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];   //此处如果索引值 ...

  6. Run-Time Check Failure #2 - Stack around the variable 's' was corrupted. 出现了 。

    程序中存在内存越界,注意数组大小和数据大小.

  7. vs中“Stack around the variable was corrupted”的解决方案

    把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值 就不会报本异常.具体原因正在研究中... 如果改为其他就有exception. exce ...

  8. 运行时错误:“stack around the variable…was corrupted”

    造冰箱的大熊猫@cnblogs 2018/11/1 引发问题的代码片段如下 WORD var; scanf ( "%d", &var ); 包含上述代码的程序,编译正常,运 ...

  9. Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt

    Run-Time    Check    Failure    #2        一般是栈被破坏,你的代码可能有缓冲区溢出一类的问题. Run-Time Check Failure #2 - Sta ...

随机推荐

  1. 最简单的基于FFMPEG的音频编码器(PCM编码为AAC)

    http://blog.csdn.net/leixiaohua1020/article/details/25430449 本文介绍一个最简单的基于FFMPEG的音频编码器.该编码器实现了PCM音频采样 ...

  2. CMDB, 配置管理数据库, ITIL - ManageEngine ServiceDesk Plus

    Download Bitnami Review Board Stack click here CMDB, 配置管理数据库, ITIL - ManageEngine ServiceDesk Plus

  3. 程序员需要掌握哪些IT技能

    据Foote Partners的最新调查:如今,你掌握的 IT 技能的多少决定了你薪资的多少,但你不一定非要比开源架构师或Certified Secure Software Life Cycle Pr ...

  4. Stream消息流 和 Stream Grouping 消息流组

  5. TCP、UDP、IP包头结构分析(转)

    1.TCP数据段格式 TCP是一种可靠的.面向连接的字节流服务.源主机在传送数据前需要先和目标主机建立连接.然后,在此连接上,被编号的数据段按序收发.同时,要求对每个数据段进行确认,保证了可靠性.如果 ...

  6. javascript中的function对象

    function对象都是Function的实例: > Object.getOwnPropertyNames(Function) [ 'length', 'name', 'arguments', ...

  7. 抽象类Abstract的简单使用

    写了一个比较简单易懂的例子,如下图 AbstractBaseClass是抽象的基类,Class1,Class2是继承他的子类,并实现他的方法. //AbstractBaseClass.cs里的代码 p ...

  8. python module的结构

    python有很多module,下面是module的结构图: 拿httplib做例子,httlip module有: 4个class( HTTPConnection,HTTPSConnection,H ...

  9. Java多线程---------同步与死锁:synchronized;等待与唤醒:wait、notify、notifyAll;生命周期

    1.问题的引出 class MyThread implements Runnable{ private int ticket = 5 ; // 假设一共有5张票 public void run(){ ...

  10. 机房收费系统(VB.NET)——存储过程实战

    最初接触存储过程是在耿建玲老师的视频里,当初仅仅是草草过了一遍.仅仅是有了个印象.知道了这个名词:大二时也有SqlServer数据库这门课,只是老师没讲,自己也没看:真正对存储过程的了解来自于自学考试 ...