From d98aeba33fdc9859f994945879d0469679e6c36b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 18 Sep 2013 20:40:45 -0700 Subject: Fixing a clipboard-related application crash. I discovered this when Sekaiju crashed when I tried to copy some notes around within a track using cut and paste. Steps to reproduce: Simply create a large amount of musical material (say on the order of dozens or hundreds of events). Then in the tracks view do "select all", and try to cut or copy the material with the context popup menu, or the shortcuts. Sekaiju will crash. If not, just increase the amount of material and keep trying. With this change i have repeatedly cut, copied and pasted thousands of MIDI events, repeatedly, without any crash. The bug is that the clipboard publishing function CSekaijuDoc::SetClipboardTextPrivate9 calculates the clipboard size in characters but then allocates that many bytes for the text rather than characters! The 32 byte padding which was there doesn't help, except when the data being put into the clipboard is very small. All we need is to allocate the correct string size, in bytes, which is (length + 1) * sizeof(TCHAR). --- src/SekaijuDoc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SekaijuDoc.cpp b/src/SekaijuDoc.cpp index 270bd17..6aaf61f 100644 --- a/src/SekaijuDoc.cpp +++ b/src/SekaijuDoc.cpp @@ -1462,7 +1462,7 @@ void CSekaijuDoc::TimeMIDIStatus (long lTargetTime, MIDIStatus* pMIDIStatus[]) { BOOL CSekaijuDoc::SetClipboardTextPrivate9 (CString& strData) { TCHAR* p = NULL; HGLOBAL hGlobalMem = NULL; - if ((hGlobalMem = GlobalAlloc (GHND, strData.GetLength() + 32)) == NULL) { + if ((hGlobalMem = GlobalAlloc (GHND, (strData.GetLength() + 1) * sizeof (TCHAR))) == NULL) { //_RPTF0 (_CRT_WARN, "グローバルメモリ確保不能。コピーは失敗しました。\n"); return FALSE; } -- cgit v1.2.3