首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

Buffer overrun detected!是什么原因?该怎么解决

2012-01-05 
Buffer overrun detected!是什么原因?我的程序执行到最后时,提示Bufferoverrundetected!,然后就报错退出了

Buffer overrun detected!是什么原因?
我的程序执行到最后时,提示   Buffer   overrun   detected!,然后就报错退出了

A   buffer   overrun   has   been   detected   which   has   corrupted   the   program 's   internal   state.The   program   cannot   safely   continue   execution   and   must   now   be   terminated.

请问应该怎么解决该问题啊!以下是我执行的程序:

void   CShareazaApp::GetUpdateFlag(void)
{
CString   strHttpName=_T( "http://www.qyjz.net/AutoUpdate.asp?action=Auto ");   //   需要提交数据的页面
        CString   uFlag   =   _T( "UpdateFlag ");
CString   strFormData   =   uFlag;//   需要提交的数据

        CInternetSession   sess;
        CHttpFile*   fileGet;
        CString   strHeaders   =   _T( "Content-Type:   application/x-www-form-urlencoded ");   //   请求头

        try
        {
                fileGet=(CHttpFile*)sess.OpenURL(strHttpName);//打开文件
        }
        catch(CException*   e)
        {
                fileGet   =   0;

//网络状况不稳定
return;
                //throw;
        }

        CString   strSentence,   strGetSentence;
        if(fileGet)
        {
                DWORD   dwStatus;
                DWORD   dwBuffLen   =   sizeof(dwStatus);
                BOOL   bSuccess   =   fileGet-> QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,   &dwStatus,   &dwBuffLen);
                if(   bSuccess   &&   dwStatus> =   200   &&dwStatus <300   )
                {  
//写入用户的Cookie信息
                        BOOL   result   =   fileGet-> SendRequest(strHeaders,   (LPVOID)(LPCTSTR)strFormData,   strFormData.GetLength());
//////////////////////////////////////////////////////////////////////////////////////////////////////
                        while(fileGet-> ReadString(strSentence))         //   读取提交数据后的返回结果
                        {
                                strGetSentence   =   strGetSentence   +   strSentence;
int   nLen   =   strGetSentence.GetLength();

//***************************************
char   sBuffer[50]=   {0};
sprintf(sBuffer, "%s ",strGetSentence);

char   string[10]   =   {0};
char   string1[10]   =   {0};
strncpy(string1,sBuffer,7);

char   *ptr;
ptr   =   strpbrk(string1, "s ");


if(!ptr)
{
strncpy(string,sBuffer,6);
sprintf(string1, "%s ",string);
}

char   string2[10]   =   {0};
char   szStr[10]   =   { "#True# "};
strncpy(string2,szStr,6);

int   result;
result   =   strcmp(   string1,   string2   );
if(   result   ==   0   )
{
//版本号为TRUE,强制用户升级程序
AfxMessageBox(L "用户必须要升级客户端程序,否则不能运行主程序 ");

break;
}
else   if(   result   <   0   )
{
AfxMessageBox(L "没有找到升级标识符 ");

//版本号为FLASE,直接退出程序
break;
}
                        }
                        //AfxMessageBox(strGetSentence);   //   显示返回网页内容
                }
                else  
                {
                        strSentence.Format(L "POST出错,错误码:%d ",   dwStatus);
                        //AfxMessageBox(strSentence);

//无法打开网页,错误代码:404
if(dwStatus   ==   404)
{
fileGet-> Close();
delete   fileGet;

sess.Close();

//如果用户没有上网或网络状态有问题,则直接退出检测,运行客户端下载程序
::ShellExecute(NULL,L "open ",L "QyjzPlayer.exe ",NULL,NULL,SW_SHOWNORMAL);
ExitProcess(0);
}
                }
               
                if(   !fileGet   )
{
fileGet-> Close();
delete   fileGet;
}
        }
        else
{
                AfxMessageBox(L "不能找到网页文件! ");
}

        if(   !sess)
sess.Close();
}




[解决办法]
strncpy好像在某些情况下不会自动在字符串后便插入0.
再检查一下你的sprintf,是不是定义的缓冲区不够大。

热点排行