editor.cpp.patch (1,712 bytes)
Index: editor.cpp
===================================================================
--- editor.cpp (revision 4680)
+++ editor.cpp (working copy)
@@ -4970,22 +4970,40 @@
wchar_t *Editor::VBlock2Text(wchar_t *ptrInitData)
{
- wchar_t *CopyData=nullptr;
size_t DataSize=0;
if (ptrInitData)
+ DataSize = wcslen(ptrInitData);
+
+ size_t TotalChars = DataSize;
+
+ Edit *CurPtr=VBlockStart;
+
+ for (int Line=0; CurPtr!=nullptr && Line<VBlockSizeY; Line++,CurPtr=CurPtr->m_next)
{
- if ((CopyData = xf_wcsdup(ptrInitData)) == nullptr)
- {
+ TotalChars += CurPtr->TabPosToReal(VBlockX+VBlockSizeX) - CurPtr->TabPosToReal(VBlockX);
+ TotalChars += 2; // CRLF
+ }
+
+ ++TotalChars; // '\0'
+
+ wchar_t *CopyData=(wchar_t *)xf_malloc(TotalChars*sizeof(wchar_t));
+
+ if (!CopyData)
+ {
+ if (ptrInitData)
xf_free(ptrInitData);
- return nullptr;
- }
+ return nullptr;
+ }
+
+ if (ptrInitData)
+ {
+ wcscpy(CopyData,ptrInitData);
xf_free(ptrInitData);
- DataSize = StrLength(CopyData);
}
- Edit *CurPtr=VBlockStart;
+ CurPtr=VBlockStart;
for (int Line=0; CurPtr!=nullptr && Line<VBlockSizeY; Line++,CurPtr=CurPtr->m_next)
{
@@ -4994,22 +5012,7 @@
const wchar_t *CurStr,*EndSeq;
int Length;
CurPtr->GetBinaryString(&CurStr,&EndSeq,Length);
- size_t AllocSize=Max(DataSize+Length+3,DataSize+TBlockSizeX+3);
- wchar_t *NewPtr=(wchar_t *)xf_realloc(CopyData,AllocSize*sizeof(wchar_t));
- if (NewPtr==nullptr)
- {
- if (CopyData)
- {
- xf_free(CopyData);
- CopyData=nullptr;
- }
-
- break;
- }
-
- CopyData=NewPtr;
-
if (Length>TBlockX)
{
int CopySize=Length-TBlockX;