在函数中反复使用CString会造成Stack溢出,求解?

cjfmail 2019-05-05 06:58:06
源码如下,求大神帮忙看看,为什么总是出现0xC00000FD: Stack overflow

CFile fParseTxtFile;
if(!fParseTxtFile.Open(szFileName,CFile::modeRead)) {
AfxMessageBox(_T("文件打开失败!"));
return;
}

int nDotSize = 0;
char szReadLine[1024] = {0};
arryData.RemoveAll();

int nReadByteSize = fParseTxtFile.Read(szReadLine,1024);
CString szLinetxt;
szLinetxt = CString(szReadLine,nReadByteSize);
DWORD dwLoadValue;
unsigned char *pDotsPtr = (unsigned char*)&dwLoadValue;
unsigned char readChar = 0;
unsigned char indexDot = 0;

while(!szLinetxt.IsEmpty()) {

CString szHexInfo;

USES_CONVERSION;

while(szLinetxt.GetLength() >= 2) {

if(byteCount == 0x1BE0) {
nCount = 61;
}
szHexInfo = szLinetxt.SpanIncluding(CString("0123456789ABCDEFabcdef"));

if(szHexInfo.IsEmpty()) {
if(szLinetxt.GetLength() >= 2) {
szLinetxt = szLinetxt.Mid(1);
continue;
}
}else if(szHexInfo.GetLength() < 2) {
break;
}else if(szHexInfo.GetLength() == 2) {
readChar = _strtoi64(T2A(szHexInfo),NULL,16);
if(indexDot == 0) {
*pDotsPtr = readChar;
}else if(indexDot == 1) {
*(pDotsPtr+1) = readChar;
}else if(indexDot == 2) {
*(pDotsPtr+2) = readChar;
if(readChar & 0x80) {
*(pDotsPtr+3) = 0xFF;
}else{
*(pDotsPtr+3) = 0x00;
}
}

indexDot = indexDot + 1;

if(indexDot == 3) {
arryData.Add(dwLoadValue);
byteCount++;
indexDot = 0;
}

szLinetxt = szLinetxt.Mid(szHexInfo.GetLength()+1);

}else{
int nHexBytesSize = szHexInfo.GetLength();
int nRemoveBytes = 0;

while(szHexInfo.GetLength() >= 2) {

CString sznewHexinfo = szHexInfo.Left(2);
readChar = _wtoi(sznewHexinfo);

if(indexDot == 0) {
*pDotsPtr = readChar;
}else if(indexDot == 1) {
*(pDotsPtr+1) = readChar;
}else if(indexDot == 2) {
*(pDotsPtr+2) = readChar;
if(readChar & 0x80)
*(pDotsPtr+3) = 0xFF;
else
*(pDotsPtr+3) = 0x00;
}

indexDot = indexDot + 1;

if(indexDot == 3) {
arryData.Add(dwLoadValue);
indexDot = 0;
}

szHexInfo = szHexInfo.Mid(2);
nRemoveBytes += 2;
}

if(szLinetxt.GetLength() > nHexBytesSize) {
szLinetxt = szLinetxt.Mid(nHexBytesSize + 1);
}else{
szLinetxt = szLinetxt.Mid(nRemoveBytes);
}
}
}

nReadByteSize = fParseTxtFile.Read(szReadLine,1024);

if(nReadByteSize == 0) {
break;
}
szLinetxt = szLinetxt + CString(szReadLine,nReadByteSize);
}


fParseTxtFile.Close();
...全文
149 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cjfmail 2019-05-13
  • 打赏
  • 举报
回复
感谢 draculamx给出正解,这个问题困扰我很久,今天终于一扫云雾。
draculamx 2019-05-07
  • 打赏
  • 举报
回复
USES_CONVERSION,不要放到while循环中使用。。。

USES_CONVERSION它是在堆栈上分配空间的,也就是说你在你使用的函数未结束就不会被释放掉。所以要注意不要在一个函数中用while循环执行它,不然栈空间就马上会分配完(栈空间一般只有2M,很小)
伊航 2019-05-06
  • 打赏
  • 举报
回复
介绍一下程序背景,思路。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧