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

Run-Time Check Failure #2 - Stack around the variable 'var' was corrupted

摘要:

简介VC++.NET编译新功能,运行时错误检查,编译选项 (/RTC1, equiv. to /RTCsu)

最近把一个别人早期在VC 6下编写的一个服务移植到VC 7.1 (.NET 2003)时,突然跳出

好些运行时错误提示。

经过查询编译器和出错说明,发现了编译器的这一新特性,并修正了代码隐患:

//someheadefile.h

typedef struct tarSomeMessagePack

{

 
 
 
 
char moibleNumber[20];

 
 
 
 
....

}SomeMessagePack_T,*SomeMessagePack_Ptr;

细心的开发者可能已经发现,这里使用字符串数组下标越界了。即mobileNumber[]有效元素

下标为0到19,mobileNumber[20]是非法的。在VC 6下,编译运行并没有处任何问题,这也结

构体在内存字节对齐也有关系,实际上,mobileNumber[]在默认与8字节对齐的环境下编译链

接的,因此,后4个bit也不会被系统用到,即mobileNumber[20],mobileNumber[21],

mobileNumber[22],mobileNumber[23]系统把它空着。

尽管系统运行同几年都很正常,但

strncpy(pack.mobileNumber," ",20);

这样的代码也是危险的代码,要是有一天,把这个结构体字节对齐方式改为1,那么程序一定

在这里崩溃。

VC7.1为我们提供了一种机制,在编译选项中,增加(/RTC1, equiv. to /RTCsu)项选。当程序

运行到这里的时候,即会向我们报告这一错误。

查看相关文档,了解了这一块代码的真实意图后,我把代码改为

strncpy(pack.mobileNumber," ",19);

这一问题消失。

//someimplement.cpp

strncpy(pack.mobileNumber," ",20);

郑注:这就是一些变量的内存访问出错造成的,而且在错误对话框中明显的提出了是哪个变量访问出错,可以查这个变量得到结果。典型的错误:如定义了一个TCHAR Code[1];,结果在使用中使用到了Code[1],就产生了这个错误

Run-Time Check Failure #2 - Stack around the variable 'ucPriKey' was corrupt的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

  7. C++程序在debug模式下遇到Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call问题。

    今天遇到一个Access Violation的crash,只看crash call stack没有找到更多的线索,于是在debug模式下又跑了一遍,遇到了如下的一个debug的错误提示框: 这个是什么 ...

  8. Run-Time Check Failure #0

    Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is ...

  9. Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. 调用函数约定不同

    Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is ...

随机推荐

  1. 【web安全】第四弹:防火墙技术笔记

    参考资料: <黑客攻防演习>第二版   Ed SKoudis  Tom Liston著 <防火墙.入侵检测与VPN> 马春光 郭方方著 OSI在理论上将网络分为七层,物理层.数 ...

  2. 15个Docker基本命令及用法

    Docker入门教程:15个Docker基本命令及用法   本文中,我们将学习15个Docker命令以及命令的用法和功能,并通过实践学习它是如何工作的. AD:51CTO 网+ 第十二期沙龙:大话数据 ...

  3. Net Core Docker

    Net Core Docker轻量级的web框架   .net core现在已经有了大的发展,虽然笔者现在已经从事python开发,但是一直在关注.net的发展,在逛博客园的时候,发现有大家都会提到N ...

  4. xcode升级后, 插件失效修复

    1. 首先查看 Xcode 的 UUID,在终端执行 defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilit ...

  5. C语言中.h和.c文件解析(很精彩)

    C语言中.h和.c文件解析(很精彩)   简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析 ...

  6. Oracle 基础知识

    SQLDevelop 1. 查看数据库版本 :  select  *  from   v$version; 2. 查看表结构:        desc     TABLE_NAME 3. 查看当前连接 ...

  7. PHP错误Warning: Cannot modify header information - headers already sent by解决方法

    这篇文章主要介绍了PHP错误Warning: Cannot modify header information - headers already sent by解决方法,需要的朋友可以参考下 今天在 ...

  8. bzoj 3851: 2048 dp优化

    3851: 2048 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 22  Solved: 9[Submit][Status] Description T ...

  9. 3D触控简介:建立数字刻度应用及快速活动栏

    苹果公司通过 iPhone 6s 和 6s Plus 引入了与手机互动的全新方式:按压手势.你也许知道,苹果智能手表和苹果笔记本电脑早已具备这一功能,只是名称略有不同,为力感触控(Force Touc ...

  10. 2.5.5 使用DatePickerDialog, TimePickerDialog

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...