diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-09-18 20:40:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-09-18 20:40:45 -0700 |
commit | d98aeba33fdc9859f994945879d0469679e6c36b (patch) | |
tree | 42817f33ab305807d487fc60ad2bdecd0c19c648 | |
parent | cb6b6dd6f04db2b58d81b395bd3d1c7ae47e65dc (diff) | |
download | sekaiju-d98aeba33fdc9859f994945879d0469679e6c36b.tar.gz sekaiju-d98aeba33fdc9859f994945879d0469679e6c36b.tar.bz2 sekaiju-d98aeba33fdc9859f994945879d0469679e6c36b.zip |
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).
-rw-r--r-- | src/SekaijuDoc.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
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;
}
|