Skip to content

Commit

Permalink
Merged revision(s) 22680 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Fix] Tree view: ReleaseBuffer was called on the wrong CString object, potentially causing incorrect string comparison results during MIDI library update.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@22681 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jan 1, 2025
1 parent cf620cc commit f0e6cda
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions mptrack/View_tre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,31 +520,31 @@ void CModTree::RefreshMidiLibrary()
HTREEITEM parent = GetChildItem(m_hMidiLib);
for(UINT iMidi = 0; iMidi < 128; iMidi++)
{
DWORD dwImage = IMAGE_INSTRMUTE;
int image = IMAGE_INSTRMUTE;
s = mpt::cfmt::val(iMidi) + _T(": ") + mpt::ToCString(mpt::Charset::ASCII, szMidiProgramNames[iMidi]);
const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi;
if(!midiLib[iMidi].empty())
{
s += _T(": ") + midiLib[iMidi].GetFilename().ToCString();
dwImage = IMAGE_INSTRUMENTS;
image = IMAGE_INSTRUMENTS;
}
if(!m_tiMidi[iMidi])
{
m_tiMidi[iMidi] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
s, dwImage, dwImage, 0, 0, param, parent, TVI_LAST);
s, image, image, 0, 0, param, parent, TVI_LAST);
} else
{
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
tvi.hItem = m_tiMidi[iMidi];
tvi.pszText = stmp.GetBuffer(s.GetLength() + 1);
tvi.cchTextMax = stmp.GetAllocLength();
tvi.iImage = tvi.iSelectedImage = dwImage;
tvi.iImage = tvi.iSelectedImage = image;
GetItem(&tvi);
s.ReleaseBuffer();
if(s != stmp || tvi.iImage != (int)dwImage)
stmp.ReleaseBuffer();
if(tvi.iImage != image || s != stmp)
{
SetItem(m_tiMidi[iMidi], TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
s, dwImage, dwImage, 0, 0, param);
s, image, image, 0, 0, param);
}
}
if((iMidi % 8u) == 7u)
Expand All @@ -555,32 +555,32 @@ void CModTree::RefreshMidiLibrary()
// Midi Percussions
for(UINT iPerc = 24; iPerc <= 84; iPerc++)
{
DWORD dwImage = IMAGE_NOSAMPLE;
int image = IMAGE_NOSAMPLE;
s = mpt::ToCString(CSoundFile::GetNoteName((ModCommand::NOTE)(iPerc + NOTE_MIN), CSoundFile::GetDefaultNoteNames()))
+ _T(": ") + mpt::ToCString(mpt::Charset::ASCII, szMidiPercussionNames[iPerc - 24]);
const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc;
if(!midiLib[iPerc | 0x80].empty())
{
s += _T(": ") + midiLib[iPerc | 0x80].GetFilename().ToCString();
dwImage = IMAGE_SAMPLES;
image = IMAGE_SAMPLES;
}
if(!m_tiPerc[iPerc])
{
m_tiPerc[iPerc] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
s, dwImage, dwImage, 0, 0, param, parent, TVI_LAST);
s, image, image, 0, 0, param, parent, TVI_LAST);
} else
{
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
tvi.hItem = m_tiPerc[iPerc];
tvi.pszText = stmp.GetBuffer(s.GetLength() + 1);
tvi.cchTextMax = stmp.GetAllocLength();
tvi.iImage = tvi.iSelectedImage = dwImage;
tvi.iImage = tvi.iSelectedImage = image;
GetItem(&tvi);
s.ReleaseBuffer();
if(s != stmp || tvi.iImage != (int)dwImage)
stmp.ReleaseBuffer();
if(tvi.iImage != image || s != stmp)
{
SetItem(m_tiPerc[iPerc], TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
s, dwImage, dwImage, 0, 0, param);
s, image, image, 0, 0, param);
}
}
}
Expand Down

0 comments on commit f0e6cda

Please sign in to comment.