make sure null pointer won't be dereferenced

Song::Empty() does the check.
This commit is contained in:
Andrzej Rybczak
2009-09-23 04:28:26 +02:00
parent 08cb912424
commit 01c138e680
2 changed files with 7 additions and 4 deletions

View File

@@ -122,7 +122,7 @@ void MPD::Song::Clear()
bool MPD::Song::Empty() const 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 bool MPD::Song::isFromDB() const
@@ -482,7 +482,10 @@ MPD::Song &MPD::Song::operator=(const MPD::Song &s)
return *this; return *this;
if (itsSong) if (itsSong)
mpd_song_free(itsSong); mpd_song_free(itsSong);
if (itsFile)
delete [] itsFile;
itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0); itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0);
itsFile = s.itsFile ? strdup(s.itsFile) : 0;
itsNewName = s.itsNewName; itsNewName = s.itsNewName;
itsSlash = s.itsSlash; itsSlash = s.itsSlash;
itsHash = s.itsHash; itsHash = s.itsHash;

View File

@@ -193,8 +193,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
{ {
if (!Playlist::BlockUpdate) if (!Playlist::BlockUpdate)
{ {
np = Mpd.GetCurrentSong(); if (!(np = Mpd.GetCurrentSong()).Empty())
if (Mpd.isPlaying())
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
bool was_filtered = myPlaylist->Items->isFiltered(); bool was_filtered = myPlaylist->Items->isFiltered();
@@ -297,6 +296,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
} }
case psPlay: case psPlay:
{ {
if (!np.Empty())
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
player_state = Config.new_design ? "[playing]" : "Playing: "; player_state = Config.new_design ? "[playing]" : "Playing: ";
Playlist::ReloadRemaining = 1; Playlist::ReloadRemaining = 1;