为什么会崩溃?我该如何修复它
Why is this crashing? How do I fix it?
这是我的代码(C++)。
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
using namespace std;
void rotaryxorencrypt(int dat[],int len){
------------------------------
}
void encrypt(int dat[],int len){
rotaryxorencrypt(dat,len);
}
void decrypt(int dat[],int len){
}
int main() {
fstream file;
fstream *fileptr=&file;
file.open("tmp",ios::in);
string line;
string *lineptr=&line;
int x;
int *xptr=&x;
int cont=0;
int *contptr=&cont;
int len;
int *lenptr=&len;
stringstream ss;
stringstream *ssptr=&ss;
string cryption;
string *cryptionptr=&cryption;
getline(*fileptr,*lineptr);
try{
if(*lineptr=="encryption"){
*cryptionptr="encrypt";
}else if(*lineptr=="decrypt"){
*cryptionptr="decryption";
} else {
cout<<"Unknown Cryptography Type - "<<*lineptr<<endl;
throw 0;
}
getline(*fileptr,*lineptr);
*ssptr<<*lineptr;
*ssptr>>*xptr;
ss.str("");
ss.clear();
*lenptr=*xptr;
int *dataptr;
dataptr=new int[*lenptr];
cout<<"Loading Formatted Data"<<endl;
while ( getline (*fileptr, *lineptr) ) {
*ssptr<<*lineptr;
*ssptr>>*xptr;
ss.str("");
ss.clear();
dataptr[cont]=*xptr;
cont++;
}
file.close();
delete lineptr;
delete xptr;
delete contptr;
delete ssptr;
delete fileptr;
------------------
if(*cryptionptr=="encrypt"){
cout<<"Beginning Encryption Process."<<endl;
cout<<dataptr[0]<<endl;
encrypt(dataptr,len);
cout<<dataptr[0]<<endl;
cout<<"Outputting Encrypted Data."<<endl;
}else if(*cryptionptr=="decrypt"){
cout<<"Beginning Decryption Process."<<endl;
decrypt(dataptr,len);
cout<<"Outputting Decrypted Data."<<endl;
}
cout<<"Clearing Cache."<<endl;
delete []dataptr;
delete cryptionptr;
delete lenptr;
}catch(int x){
if(x==0){
cout<<"Clearing Cache."<<endl;
delete fileptr;
delete lineptr;
delete xptr;
delete contptr;
delete ssptr;
delete fileptr;
}else{
cout<<"Unknown Error - Cannot Clear The Cache."<<endl;
}
}
cout<<"here"<<endl;
return 0;
cout<<"here"<<endl;
}
注意return 0;
之前和之后的cout<<"here"<<endl;
。如果没有它们,我也会遇到同样的问题,所以它们不是问题所在,但它会执行第一个cout<<"here"<<endl;
,但会在第二个之前崩溃。如果我删除第二个,它也会做同样的事情,如果我删除第一个,它就会崩溃,因此它会崩溃在return 0;
上。为什么会发生这种情况。(附言:这是另一个加密项目的一部分(可能是敏感部分[不是崩溃点或代码错误]被变成了"------------------"(这不是实际的代码)。
去掉所有指针和所有delete
s。此处没有使用new
创建任何内容,因此没有任何内容可删除。好的,有dataptr
应该删除。但这在所有的噪音中都很难找到。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- Boost Graph Library,修复节点大小
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 程序崩溃并显示"std::out_of_range"错误
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 如何修复条件复制期间发生的崩溃
- 如何在导致应用程序崩溃的代码中修复指令
- 虚幻引擎v4.18为什么这会导致崩溃以及我该如何修复
- C++ 尝试通过内存中的地址调用函数时程序崩溃(如何修复?
- 为什么会崩溃?我该如何修复它
- 修复不可预测的崩溃
- 如何修复导致程序崩溃的错误
- 代码崩溃,如果没有打印在循环上,我该如何修复
- 修复了OpenSSL中SIGILL导致的崩溃
- 如何修复运行时崩溃-QObject::setParent:无法设置父级,新的父级在不同的线程中
- C++猜数字游戏在其他计算机上崩溃并无限循环修复
- 如何调查和修复 libpjsua2.so 崩溃