问题描述
- 程序运行结束后总是显示:Run-Time Check Failure #2
-
程序运行结束后总是显示:Run-Time Check Failure #2 - Stack around the variable 'cmd_value' was corrupted.
程序过程运行正确,调试发现程序运行结束之后就会报告这个错误。
而且**只有d的数值在0到1(不包括1)**才会发生这样的错误。
我的编程环境是vs2010.double d=0;BYTE cmd_star[]=""$"";BYTE cmd_cmd[]=""001"";BYTE cmd_mid[]="";char cmd_value[7];_gcvt_s(cmd_valuesizeof(cmd_value)d5);BYTE cmd_end[]=""#"";BYTE cmd2[13];memcpy(cmd2cmd_starsizeof(char));memcpy(cmd2+1cmd_cmd3*sizeof(char));memcpy(cmd2+4cmd_midsizeof(char));memcpy(cmd2+5cmd_value6*sizeof(char));memcpy(cmd2+11cmd_endsizeof(char));CWnd * pMain=(CWnd*)AfxGetMainWnd();Eol.hEvent=CreateEvent(NULL TRUE // manual-reset event FALSE // not signaled NULL);if(!::SetCommState(hComFile&m_BCD)){ //AfxMessageBox(""SetCommState() error!""); errmsg = ""串口设置失败!""; p = (LPSTR)(LPCTSTR)errmsg; ::SendMessage(pMain->m_hWndUM_ERRORMSG0(LPARAM)p); return ;}::EscapeCommFunction(hComFileSETDTR);if(WriteData(cmd213)!=13){ //AfxMessageBox(""Write com error!""); errmsg = ""串口写入失败!""; p = (LPSTR)(LPCTSTR)errmsg; ::SendMessage(pMain->m_hWndUM_ERRORMSG0(LPARAM)p); return;}if (Eol.hEvent!=NULL){ ResetEvent(Eol.hEvent);}CloseHandle(Eol.hEvent);
解决方案
BYTE cmd_star[]=""$"";
BYTE cmd_cmd[]=""001"";
BYTE cmd_mid[]="";
这些都是常量,而且大小都很小。你把这些都定义的大一些不可以么
解决方案二:
Run-Time Check Failure #2
Run-Time Check Failure #2
Run-Time Check Failure #2
解决方案三:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案四:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案五:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案六:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案七:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案八:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案九:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_
解决方案十:
希望对你有所帮助和启发....http://zhidao.baidu.com/link?url=MWxVy6S4p4gByCdW3DmZyNeLzFYS0SY3_0Qyuearsn63amu3tYTFrk5wp5935WF0OsqKmm5QoYB8whvsVhWC4_