diff --git a/SourceCode/Code2026/CoreLibrary/AcDbX3dSolid.cpp b/SourceCode/Code2026/CoreLibrary/AcDbX3dSolid.cpp index 615fd80..5b181d4 100644 --- a/SourceCode/Code2026/CoreLibrary/AcDbX3dSolid.cpp +++ b/SourceCode/Code2026/CoreLibrary/AcDbX3dSolid.cpp @@ -129,11 +129,15 @@ bool FormatScriptFromSection(CString& sScr,STSection* pSection) if (file.Open(sFullPath,CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt,(UINT)dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - sRegionScrp = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + sRegionScrp = CString(pszTxt, (int)nRead); delete [] pszTxt; file.Close(); @@ -2900,7 +2904,11 @@ bool AcDbX3dSolid::CreateFromSat(LPCTSTR pszSatFile,double dUnitScale) //上一级目录 int nPos = sFullPath.ReverseFind(_T('\\')); CString sPath = sFullPath.Mid(0,nPos + 1); - sFullPath = sPath + _T("temp\\temp.sat"); + + // 每次用唯一文件名:多个 CAD 实例同时从 SAT 重建时不会互相覆盖 + static LONG s_nSatSeq = 0; + sFullPath.Format(_T("%stemp\\temp_%lu_%ld.sat"),(LPCTSTR)sPath + ,(unsigned long)::GetCurrentProcessId(),(long)::InterlockedIncrement(&s_nSatSeq)); CFile file; if (file.Open(sFullPath,CFile::modeCreate|CFile::modeWrite)) @@ -2912,6 +2920,8 @@ bool AcDbX3dSolid::CreateFromSat(LPCTSTR pszSatFile,double dUnitScale) AcDbVoidPtrArray arPtr; AcDbBody::acisIn(sFullPath,arPtr); + ::DeleteFile(sFullPath); + //按照体积从大到小排序 Sort3dSolidByVol(arPtr); diff --git a/SourceCode/Code2026/CoreLibrary/AecDbEarthWormFitting.cpp b/SourceCode/Code2026/CoreLibrary/AecDbEarthWormFitting.cpp index fb28f14..3ae20db 100644 --- a/SourceCode/Code2026/CoreLibrary/AecDbEarthWormFitting.cpp +++ b/SourceCode/Code2026/CoreLibrary/AecDbEarthWormFitting.cpp @@ -580,11 +580,15 @@ CString GetSectionScr(AcDbRegion* pReg) if (file.Open(sFullPath,CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt,(UINT)dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - sRegionScrp = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + sRegionScrp = CString(pszTxt, (int)nRead); delete [] pszTxt; file.Close(); diff --git a/SourceCode/Code2026/EarthWormCmd/DGJMDlg.cpp b/SourceCode/Code2026/EarthWormCmd/DGJMDlg.cpp index 7f5e0b3..237efea 100644 --- a/SourceCode/Code2026/EarthWormCmd/DGJMDlg.cpp +++ b/SourceCode/Code2026/EarthWormCmd/DGJMDlg.cpp @@ -951,11 +951,15 @@ void CDGJMDlg::OnBnClickedBtaddtodb() if (file.Open(sFullPath,CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt,dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - sRegionScrp = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + sRegionScrp = CString(pszTxt, (int)nRead); delete [] pszTxt; file.Close(); diff --git a/SourceCode/Code2026/EarthWormCmd/GJYXJMDlg.cpp b/SourceCode/Code2026/EarthWormCmd/GJYXJMDlg.cpp index 9dc4c40..e2f6004 100644 --- a/SourceCode/Code2026/EarthWormCmd/GJYXJMDlg.cpp +++ b/SourceCode/Code2026/EarthWormCmd/GJYXJMDlg.cpp @@ -9418,11 +9418,15 @@ bool FormatScriptFromSection(CString& sScr,STSection* pSection) if (file.Open(sFullPath,CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt,dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - sRegionScrp = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + sRegionScrp = CString(pszTxt, (int)nRead); delete [] pszTxt; file.Close(); diff --git a/SourceCode/Code2026/Pool3dCmd/JMDBDlg.cpp b/SourceCode/Code2026/Pool3dCmd/JMDBDlg.cpp index 47b59ca..e504960 100644 --- a/SourceCode/Code2026/Pool3dCmd/JMDBDlg.cpp +++ b/SourceCode/Code2026/Pool3dCmd/JMDBDlg.cpp @@ -186,11 +186,15 @@ void CJMDBDlg::OnBnClickedButton2() if (file.Open(sFullPath, CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt, dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - m_sRegScr = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + m_sRegScr = CString(pszTxt, (int)nRead); DELETE_ARR_(pszTxt); file.Close(); diff --git a/SourceCode/Code2026/Pool3dCmd/JMSJDlg.cpp b/SourceCode/Code2026/Pool3dCmd/JMSJDlg.cpp index 93f196c..d6e8cb3 100644 --- a/SourceCode/Code2026/Pool3dCmd/JMSJDlg.cpp +++ b/SourceCode/Code2026/Pool3dCmd/JMSJDlg.cpp @@ -152,11 +152,15 @@ void CJMSJDlg::OnBnClickedBtaddtodb() if (file.Open(sFullPath, CFile::modeRead)) { ULONGLONG dwFileLength = file.GetLength(); - char* pszTxt = new char[dwFileLength]; + int nLen = (int)dwFileLength; - file.Read(pszTxt, dwFileLength); + // 补终止符并按实际读到的长度赋值,避免把未初始化内存当字符串读 + char* pszTxt = new char[nLen + 1]; + ::memset(pszTxt, 0, nLen + 1); - sRegionScrp = pszTxt; + UINT nRead = file.Read(pszTxt, nLen); + + sRegionScrp = CString(pszTxt, (int)nRead); DELETE_ARR_(pszTxt); file.Close();