晚上花了几个小时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. HW5.24

    import java.util.Calendar; public class Solution { public static void main(String[] args) { System.o ...

  2. Devlop Win 8 and Windows Phone App for Microsoft Dynamics CRM

    Microsoft Dynamics CRM App for Windows Phone http://www.windowsphone.com/en-us/store/app/dynamics-cr ...

  3. PC-ADSL开机自动拨号方法

    方法一:把adsl拨号的快捷方式放到“开始”菜单中“所有程序”中的“启动”中. 再到“控制面板”中的“网络连接”中找到你用的拨号连接,鼠标右键点击选择“属性”.然后,在窗口上部选择“选项”,把“拨号选 ...

  4. 教程-隐藏/显示任务栏-程序不在任务显示-全面控制Windows

    1.隐藏任务条 var  h:THandle; //变量h:=FindWindow('Shell_TrayWnd',nil);ShowWindow(h,SW_hide); 2.显示任务条h:=Find ...

  5. mongodb的优化

    1:使用索引 ,同时对索引排序,[比如mongodb对时间做索引都用-1降序哈,这样查询最新的速度很快],注意组合索引中字段的顺序要和查询时字段的顺序一致哈, 用find().explain()检查查 ...

  6. SweetAlert 使用

    $(".delete").click(function(){ var work_name = $(this).data('name'); var item_id = $(this) ...

  7. Redis集群战法整理

    单机及集群搭建 http://www.codeceo.com/article/distributed-caching-redis-server.html 主从复制设置 Redis服务器复制(主—从配置 ...

  8. 跟我学SpringMVC目录汇总贴、PDF下载、源码下载

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. Nginx入门之两种handler函数的挂载方式

    请在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 接着上次的文章,今天研究<深入理解Nginx模块开发与架构解析>一书中给出的mytest的例子,发现和 /tengine.t ...

  10. 分布式助手Zookeeper(四)

    分布式助手Zookeeper(四)博客分类: Zookeeper zookeeper配置同步zookeeper编程 Zookeeper是分布式环境下一个重要的组件,因为它能在分布式环境下,给我带来很多 ...