请在下面的代码片段中找出可能有错误或有安全隐患的地方,并写出错误的原因。
2013-07-01 00:12
465 查看
请在下面的代码片段中找出可能有错误或有安全隐患的地方,并写出错误的原因。
struct complex_t
{
int real;
int imag;
};
//若:create(complex_t&* p则 cannot convert from 'struct complex_t *' to'struct complex_t **
int create(complex_t*p,unsigned int n) //指针参数问题,应当传引用create(complex_t * &p, ..
{
p=new complex_t
; //new 与delete的对应
if(p==NULL){
return -1;
}
return 0;
}
int compute()
{
//implement
complex_t* comps;
unsigned int num = 0;
cin>>num;
if(create(comps,num)<0){//localvariable 'comps' used without having been initialized
cerr<<”create comps failed!”<<endl;
return -1;
}
long int sum=0;
unsigned int pos = 0;
cin>>pos;
while(pos<num){
cin>>comps[pos].real>>comps[pos].imag;
cin>>comps[pos+1].real>>comps[pos+1].imag;
sum+=comps[pos].real*comps[pos+1].real+comps[pos].imag*comps[pos+1].imag;
pos+=2; //一次加2,万一pos与num相差为奇数。
}
cout<<”sum is”<<sum<<endl;
return 0;
}
struct complex_t
{
int real;
int imag;
};
//若:create(complex_t&* p则 cannot convert from 'struct complex_t *' to'struct complex_t **
int create(complex_t*p,unsigned int n) //指针参数问题,应当传引用create(complex_t * &p, ..
{
p=new complex_t
; //new 与delete的对应
if(p==NULL){
return -1;
}
return 0;
}
int compute()
{
//implement
complex_t* comps;
unsigned int num = 0;
cin>>num;
if(create(comps,num)<0){//localvariable 'comps' used without having been initialized
cerr<<”create comps failed!”<<endl;
return -1;
}
long int sum=0;
unsigned int pos = 0;
cin>>pos;
while(pos<num){
cin>>comps[pos].real>>comps[pos].imag;
cin>>comps[pos+1].real>>comps[pos+1].imag;
sum+=comps[pos].real*comps[pos+1].real+comps[pos].imag*comps[pos+1].imag;
pos+=2; //一次加2,万一pos与num相差为奇数。
}
cout<<”sum is”<<sum<<endl;
return 0;
}
相关文章推荐
- 一、 找出函数中存在的问题。以下题目均在Lab05项目中完成。2、 找出项目中存在的缺陷,并给出解决的方案(至少3个,不包含下面那个举例)。 说明:这里所说的缺陷不一定都是错误,而是明显需要改进的地方。 如:不可以无限输入密码,容易被暴力破解,存在安全隐患。
- 下面代码出现错误:[下面的框架可能不正确和/或缺失,没有为 kernel32.dll 加载符号] ,请问是怎么回事啊?
- 怎样才能写出尽可能让编译器找出潜在错误的代码?
- 请找出下面这段代码的错误
- 请大家看一下一个c语言中的链表问题,下面的代码是有错误的!!请大家说出错误的原因,以及修改的方法!!!
- C经典面试题,下面的代码的目的是使字符串倒序,如“abcd”倒序后变为"dcba",请找出错误,并改正
- String内存溢出异常(错误)可能的原因及解决方式
- Microsoft VBScript 编译器错误 错误原因 代码大全
- sqlserver2012还原失败的原因(错误代码3154)
- 我现在是一点也看不明白。。只知道写出那些代码就会出现那种结果 你开始学的时候看的明白吗 不明白原因。 主要学C吗
- 泛型 要注意的地方 下面的代码不能执行
- vmware workstation 提示程序包可能有错,错误代码 29141 & 提示不可恢复错误: (vcpu-0)
- Spring《注解实现aop: can't find referenced pointcut..可能出现错误的原因》
- javascript代码运行不出来执行错误的可能情况整理
- “不能执行已释放的Script代码”错误的原因及解决办法
- 第五题:下面的程序有问题吗?如果有,请指出可能出错的地方,以及如何修改
- java常见错误以及可能原因
- 空指向异常错误的可能原因
- Invalid bound statement (not found)错误的可能原因
- 支付宝手机网站支付 错误代码 insufficient-isv-permissions 错误原因: ISV权限不足