VC++出现错误: Stack around the variable was corrupted 的解决方案
2012-12-06 19:43
1371 查看
Vs2010 Debug 一个C++项目完全没有问题,但是运行时出现Stack around the variable was corrupted错误。
部分代码如下:
CString strSql;
strSql = "select * from emp";
CMyODBC db;
db.ConnectDB("daliu","", "");
CODBCSet set;
try
{
db.PrepareSql(strSql, set);//在没用套try{}catch{}前调用此方法时出现运行时错误。
}
catch (CException* e)
{
}
1:加上try{}catch{}或者是
2:把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值
就不会报错了。
代码如下:
#include <stdio.h>
#include <Windows.h>
// in 64 win7 vs2010...here have to define a 8s' space.. so defined e00_date.wee
struct e00_date{
unsigned short int year;
unsigned short int month;
unsigned short int day;
//unsigned char tt;
//unsigned short week;
};
typedef struct e00_date e00_date;
void main()
{
e00_date date;
unsigned short int sum=0;
puts("input a date (format: yyyy/mm/dd)");
scanf("%d/%d/%d",&date.year,&date.month,&date.day);
if(date.month>12||date.month<1)
{
puts("please input a viald value");
system("pause");
exit(0);
}
sum+=date.day;
switch(date.month)
{case 12: sum+=30;
case 11: sum+=31;
case 10: sum+=30;
case 9: sum+=31;
case 8: sum+=31;
case 7: sum+=30;
case 6: sum+=31;
case 5: sum+=30;
case 4: sum+=31;
case 3: sum+=28;
case 2: sum+=31;
case 1: break;
}
if(((date.month%4==0)&&(date.month%100!=0))||(date.month%400==0))
if(date.month>2)
sum++;
printf("\nthis the %hu days in %4hu/%02hu/%02hu(yyy/mm/dd)",sum,date.year,date.month,date.day);system("pause");
}
#################################################
今天遇到一个错误如题,在程序结尾来了这么一下。
解决方法一:
但是在struct e00_date里面在加一个char或者 short。就正常了(struct 注释的2个变量),添加变量是为了使struct的size大>=8,64位的系统,所以猜想是这里有问题?!但是没道理啊,其他2,4,6大小的struct都没问题。。
解决方法二:
网上找,都说是越界了。。然后debug一个一个找,数据都能正确的存到变量里。后面没办法了,一个一个的格式化输入输出,
scanf那,把%d改成%hu,最终就OK了。还是很纳闷。。程序运行到system("pause");最后面了,才报错,前面都过的去,怎么这里这么就出来了。。(1.这里都没有访问数据读取了。怎么出现错误。2.存储空间数据也是正确存入了,也就是说在short的2个字节范围内没有异常数据。它凭什么就被corrupted。就算输入1998/9/25(0x07ce/0x0009/0x0019)可能会变成(0x000007ce,0x00000009,0x00000019)最多就是把2个字节以外的0丢失嘛。。
真心搞不通啊。是不是理解有错~~求解释~~~~~
部分代码如下:
CString strSql;
strSql = "select * from emp";
CMyODBC db;
db.ConnectDB("daliu","", "");
CODBCSet set;
try
{
db.PrepareSql(strSql, set);//在没用套try{}catch{}前调用此方法时出现运行时错误。
}
catch (CException* e)
{
}
1:加上try{}catch{}或者是
2:把 project->配置属性->c/c++->代码生成->基本运行时检查 为 默认值
就不会报错了。
代码如下:
#include <stdio.h>
#include <Windows.h>
// in 64 win7 vs2010...here have to define a 8s' space.. so defined e00_date.wee
struct e00_date{
unsigned short int year;
unsigned short int month;
unsigned short int day;
//unsigned char tt;
//unsigned short week;
};
typedef struct e00_date e00_date;
void main()
{
e00_date date;
unsigned short int sum=0;
puts("input a date (format: yyyy/mm/dd)");
scanf("%d/%d/%d",&date.year,&date.month,&date.day);
if(date.month>12||date.month<1)
{
puts("please input a viald value");
system("pause");
exit(0);
}
sum+=date.day;
switch(date.month)
{case 12: sum+=30;
case 11: sum+=31;
case 10: sum+=30;
case 9: sum+=31;
case 8: sum+=31;
case 7: sum+=30;
case 6: sum+=31;
case 5: sum+=30;
case 4: sum+=31;
case 3: sum+=28;
case 2: sum+=31;
case 1: break;
}
if(((date.month%4==0)&&(date.month%100!=0))||(date.month%400==0))
if(date.month>2)
sum++;
printf("\nthis the %hu days in %4hu/%02hu/%02hu(yyy/mm/dd)",sum,date.year,date.month,date.day);system("pause");
}
#################################################
今天遇到一个错误如题,在程序结尾来了这么一下。
解决方法一:
但是在struct e00_date里面在加一个char或者 short。就正常了(struct 注释的2个变量),添加变量是为了使struct的size大>=8,64位的系统,所以猜想是这里有问题?!但是没道理啊,其他2,4,6大小的struct都没问题。。
解决方法二:
网上找,都说是越界了。。然后debug一个一个找,数据都能正确的存到变量里。后面没办法了,一个一个的格式化输入输出,
scanf那,把%d改成%hu,最终就OK了。还是很纳闷。。程序运行到system("pause");最后面了,才报错,前面都过的去,怎么这里这么就出来了。。(1.这里都没有访问数据读取了。怎么出现错误。2.存储空间数据也是正确存入了,也就是说在short的2个字节范围内没有异常数据。它凭什么就被corrupted。就算输入1998/9/25(0x07ce/0x0009/0x0019)可能会变成(0x000007ce,0x00000009,0x00000019)最多就是把2个字节以外的0丢失嘛。。
真心搞不通啊。是不是理解有错~~求解释~~~~~
相关文章推荐
- Opencv中调用FileStorage出现错误“Stack around the variable '*' was corrupted.”
- 错误:stack around the variable * was corrupted
- Stack around the variable was corrupted 解决方案
- Stack around the variable was corrupted 解决方案 ---增大栈空间
- VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法
- 【Coding】Stack around the variable was corrupted 解决方案
- VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法
- 解决MFC运行时错误:“Stack around the variable 'dlg' was corrupted. ”
- vs中“Stack around the variable was corrupted”的解决方案
- VS2008中Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted 错误解决方法
- stack around the variable "xxx"was corrupted.
- C error :Run-Time Check Failure #2 - Stack around the variable 'b' was corrupted.
- vs c库连接 Mysql后, 关闭M时,提示 Run-Time Check Failure #2 - Stack around the variable 'mysql' was corrupted.
- Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.
- 关于在VS2008中的Stack around the variable '' was corrupted.即(堆栈被破坏周围的变量)解决办法
- Run-Time Check Failure #2 - Stack around the variable ‘ ’ was corrupted.
- Run-Time Check Failure #2 - Stack around the variable 'chCommand' was corrupted.
- Run-Time Check Failure #2 - Stack around the variable 'var' was corrupted
- (转)奇怪的Stack around the variable was corrupted现象解析 以及 sprintf 的奇怪现象?
- itoa()函数 Stack around the variable 'strtemp' was corrupted !!!???