高手们请帮个忙。VC+ debug下oK,realase下有错。解决办法
高手们请帮个忙。。VC+ debug下oK,realase下有错。
麻烦各位高手帮小弟诊断下代码看那些的不对。谢谢。
//判断用户登录密码是否正确
bool CFileOpenNewToolDlg::isRightPWD(CString csPwd,CString willFinderFile){
//取得当前项目下的一个文件的摘要信息
CFileFind finder;
CString file_pro("");
char str_fileArray[255] = "";
char* fileProChar="";
BOOL bright = finder.FindFile(willFinderFile);
if(bright){
bright = finder.FindNextFile();
//-------读取当前文件路径存入csfileNamePath,并将其转为char *pePath_from11中。
CString csfileNamePath = _T(finder.GetFilePath());
char *pePath_from11 =(char *)malloc(csfileNamePath.GetLength()+1);
memcpy(pePath_from11,csfileNamePath.GetBuffer(0),csfileNamePath.GetLength());
pePath_from11[csfileNamePath.GetLength()] = '\0';
csfileNamePath.ReleaseBuffer();
//--------调用dll的GetPro接口,取出当前文件pePath_from11的摘要属性------
fileProChar = GetPro(pePath_from11,12);
//-------将当前文件pePath_from11的摘要属性 赋值 到str_fileArray 字符串中
strcpy(str_fileArray,fileProChar);
str_fileArray[strlen(fileProChar)] = '\0';
//--------释放pePath_from11指针----------------
free(pePath_from11);
}else{
MessageBox("当前没有可解密的文件,不能打开程序!","错误提示",MB_ICONSTOP);
exit(0);
}
//将CString类型csPwd转换为char* sPwd。--------
char* sPwd = (char *)malloc(csPwd.GetLength()+1); //用户输入密码
memcpy(sPwd,csPwd.GetBuffer(0),csPwd.GetLength());
MessageBox("isRightPWD33");
sPwd[csPwd.GetLength()] = '\0';
csPwd.ReleaseBuffer();
//将当前输入的用户密码sPwd 取得MD5的摘要信息pwdMD5Digest-------------
char* pwdMD5Digest = new char[64]; //存储密码的摘要信息
pwdMD5Digest[64] ='\0';
MD5Encrypt((unsigned char *)sPwd, strlen(sPwd), pwdMD5Digest);
//比较pwdMD5Diges 和str_fileArray是否相同--------------------
if(strcmp(pwdMD5Digest,str_fileArray)==0){
initGetFileKey(str_fileArray);
return true;
}else{
return false;
}
}
------解决方案--------------------
基本上应该是数组或者指针使用上有点小问题导致的。
------解决方案--------------------
char* pwdMD5Digest = new char[64]; //存储密码的摘要信息
pwdMD5Digest[64] ='\0';
变成:
pwdMD5Digest[63]='\0';
------解决方案--------------------
ls正解,另外函数结尾加上 delete[] pwdMD5Digest;
麻烦各位高手帮小弟诊断下代码看那些的不对。谢谢。
//判断用户登录密码是否正确
bool CFileOpenNewToolDlg::isRightPWD(CString csPwd,CString willFinderFile){
//取得当前项目下的一个文件的摘要信息
CFileFind finder;
CString file_pro("");
char str_fileArray[255] = "";
char* fileProChar="";
BOOL bright = finder.FindFile(willFinderFile);
if(bright){
bright = finder.FindNextFile();
//-------读取当前文件路径存入csfileNamePath,并将其转为char *pePath_from11中。
CString csfileNamePath = _T(finder.GetFilePath());
char *pePath_from11 =(char *)malloc(csfileNamePath.GetLength()+1);
memcpy(pePath_from11,csfileNamePath.GetBuffer(0),csfileNamePath.GetLength());
pePath_from11[csfileNamePath.GetLength()] = '\0';
csfileNamePath.ReleaseBuffer();
//--------调用dll的GetPro接口,取出当前文件pePath_from11的摘要属性------
fileProChar = GetPro(pePath_from11,12);
//-------将当前文件pePath_from11的摘要属性 赋值 到str_fileArray 字符串中
strcpy(str_fileArray,fileProChar);
str_fileArray[strlen(fileProChar)] = '\0';
//--------释放pePath_from11指针----------------
free(pePath_from11);
}else{
MessageBox("当前没有可解密的文件,不能打开程序!","错误提示",MB_ICONSTOP);
exit(0);
}
//将CString类型csPwd转换为char* sPwd。--------
char* sPwd = (char *)malloc(csPwd.GetLength()+1); //用户输入密码
memcpy(sPwd,csPwd.GetBuffer(0),csPwd.GetLength());
MessageBox("isRightPWD33");
sPwd[csPwd.GetLength()] = '\0';
csPwd.ReleaseBuffer();
//将当前输入的用户密码sPwd 取得MD5的摘要信息pwdMD5Digest-------------
char* pwdMD5Digest = new char[64]; //存储密码的摘要信息
pwdMD5Digest[64] ='\0';
MD5Encrypt((unsigned char *)sPwd, strlen(sPwd), pwdMD5Digest);
//比较pwdMD5Diges 和str_fileArray是否相同--------------------
if(strcmp(pwdMD5Digest,str_fileArray)==0){
initGetFileKey(str_fileArray);
return true;
}else{
return false;
}
}
------解决方案--------------------
基本上应该是数组或者指针使用上有点小问题导致的。
------解决方案--------------------
char* pwdMD5Digest = new char[64]; //存储密码的摘要信息
pwdMD5Digest[64] ='\0';
变成:
pwdMD5Digest[63]='\0';
------解决方案--------------------
ls正解,另外函数结尾加上 delete[] pwdMD5Digest;