From 01c138e6806053cd8538aa935726226fc0020fb3 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 23 Sep 2009 04:28:26 +0200 Subject: [PATCH] make sure null pointer won't be dereferenced Song::Empty() does the check. --- src/song.cpp | 5 ++++- src/status.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/song.cpp b/src/song.cpp index c15b2608..8cab1fcd 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -122,7 +122,7 @@ void MPD::Song::Clear() bool MPD::Song::Empty() const { - return !itsSong;// || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment); + return !itsSong; } bool MPD::Song::isFromDB() const @@ -482,7 +482,10 @@ MPD::Song &MPD::Song::operator=(const MPD::Song &s) return *this; if (itsSong) mpd_song_free(itsSong); + if (itsFile) + delete [] itsFile; itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0); + itsFile = s.itsFile ? strdup(s.itsFile) : 0; itsNewName = s.itsNewName; itsSlash = s.itsSlash; itsHash = s.itsHash; diff --git a/src/status.cpp b/src/status.cpp index 7897c6f9..4e4785b5 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -193,8 +193,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *) { if (!Playlist::BlockUpdate) { - np = Mpd.GetCurrentSong(); - if (Mpd.isPlaying()) + if (!(np = Mpd.GetCurrentSong()).Empty()) WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); bool was_filtered = myPlaylist->Items->isFiltered(); @@ -297,7 +296,8 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *) } case psPlay: { - WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); + if (!np.Empty()) + WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); player_state = Config.new_design ? "[playing]" : "Playing: "; Playlist::ReloadRemaining = 1; changed.ElapsedTime = 1;