Ticket #13402: 0001-Fix-crash-with-missing-midi_settings.patch

File 0001-Fix-crash-with-missing-midi_settings.patch, 2.5 KB (added by humdinger, 8 years ago)

Fixing patch

  • src/preferences/media/MidiSettingsView.cpp

    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()  
    200200{
    201201    struct BPrivate::midi_settings settings;
    202202    if (BPrivate::read_midi_settings(&settings) == B_OK)
    203         fActiveSoundFont = new BString(settings.soundfont_file);
     203        fActiveSoundFont.SetTo(settings.soundfont_file);
    204204}
    205205
    206206
    207207void
    208208MidiSettingsView::_SaveSettings()
    209209{
    210     fActiveSoundFont = new BString(_SelectedSoundFont());
    211     if (fActiveSoundFont->Length() > 0) {
     210    fActiveSoundFont = _SelectedSoundFont();
     211    if (fActiveSoundFont.Length() > 0) {
    212212        struct BPrivate::midi_settings settings;
    213         strlcpy(settings.soundfont_file, fActiveSoundFont->String(),
     213        strlcpy(settings.soundfont_file, fActiveSoundFont.String(),
    214214            sizeof(settings.soundfont_file));
    215215        BPrivate::write_midi_settings(settings);
    216216    }
    MidiSettingsView::_SelectActiveSoundFont()  
    228228    }
    229229    for (int32 i = 0; i < fListView->CountItems(); i++) {
    230230        BStringItem* item = (BStringItem*)fListView->ItemAt(i);
    231         if (!strcmp(item->Text(), fActiveSoundFont->String())) {
     231        if (!strcmp(item->Text(), fActiveSoundFont.String())) {
    232232            fListView->Select(i);
    233233            break;
    234234        }
  • src/preferences/media/MidiSettingsView.h

    diff --git a/src/preferences/media/MidiSettingsView.h b/src/preferences/media/MidiSettingsView.h
    index 2093b2d..9e226da 100644
    a b  
    99
    1010#include "MediaViews.h"
    1111
     12#include "String.h"
     13
    1214class BButton;
    1315class BListView;
    14 class BString;
    1516class BStringView;
    1617
    1718class MidiSettingsView : public SettingsView {
    private:  
    3233    void            _UpdateSoundFontStatus();
    3334
    3435    BListView*      fListView;
    35     BString*        fActiveSoundFont;
     36    BString         fActiveSoundFont;
    3637    BStringView*    fSoundFontStatus;
    3738};
    3839