From a4eb976130c06345cea4338b0d85bd3050723c61 Mon Sep 17 00:00:00 2001
From: Humdinger <humdingerb@gmail.com>
Date: Tue, 28 Mar 2017 20:27:56 +0200
Subject: [PATCH] Fix crash with missing midi_settings
fActiveSoundFont wasn't initialized when there's no midi_settings file.
Don't allocate it on the heap, the object gets implicitely initialized to
an empty string.
Thanks to AnEvilYak for his consultation.
Fixes #13402.
---
src/preferences/media/MidiSettingsView.cpp | 10 +++++-----
src/preferences/media/MidiSettingsView.h | 5 +++--
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/preferences/media/MidiSettingsView.cpp b/src/preferences/media/MidiSettingsView.cpp
index f5720e8..1da654f 100644
a
|
b
|
MidiSettingsView::_LoadSettings()
|
200 | 200 | { |
201 | 201 | struct BPrivate::midi_settings settings; |
202 | 202 | if (BPrivate::read_midi_settings(&settings) == B_OK) |
203 | | fActiveSoundFont = new BString(settings.soundfont_file); |
| 203 | fActiveSoundFont.SetTo(settings.soundfont_file); |
204 | 204 | } |
205 | 205 | |
206 | 206 | |
207 | 207 | void |
208 | 208 | MidiSettingsView::_SaveSettings() |
209 | 209 | { |
210 | | fActiveSoundFont = new BString(_SelectedSoundFont()); |
211 | | if (fActiveSoundFont->Length() > 0) { |
| 210 | fActiveSoundFont = _SelectedSoundFont(); |
| 211 | if (fActiveSoundFont.Length() > 0) { |
212 | 212 | struct BPrivate::midi_settings settings; |
213 | | strlcpy(settings.soundfont_file, fActiveSoundFont->String(), |
| 213 | strlcpy(settings.soundfont_file, fActiveSoundFont.String(), |
214 | 214 | sizeof(settings.soundfont_file)); |
215 | 215 | BPrivate::write_midi_settings(settings); |
216 | 216 | } |
… |
… |
MidiSettingsView::_SelectActiveSoundFont()
|
228 | 228 | } |
229 | 229 | for (int32 i = 0; i < fListView->CountItems(); i++) { |
230 | 230 | BStringItem* item = (BStringItem*)fListView->ItemAt(i); |
231 | | if (!strcmp(item->Text(), fActiveSoundFont->String())) { |
| 231 | if (!strcmp(item->Text(), fActiveSoundFont.String())) { |
232 | 232 | fListView->Select(i); |
233 | 233 | break; |
234 | 234 | } |
diff --git a/src/preferences/media/MidiSettingsView.h b/src/preferences/media/MidiSettingsView.h
index 2093b2d..9e226da 100644
a
|
b
|
|
9 | 9 | |
10 | 10 | #include "MediaViews.h" |
11 | 11 | |
| 12 | #include "String.h" |
| 13 | |
12 | 14 | class BButton; |
13 | 15 | class BListView; |
14 | | class BString; |
15 | 16 | class BStringView; |
16 | 17 | |
17 | 18 | class MidiSettingsView : public SettingsView { |
… |
… |
private:
|
32 | 33 | void _UpdateSoundFontStatus(); |
33 | 34 | |
34 | 35 | BListView* fListView; |
35 | | BString* fActiveSoundFont; |
| 36 | BString fActiveSoundFont; |
36 | 37 | BStringView* fSoundFontStatus; |
37 | 38 | }; |
38 | 39 | |