From 89a476e94c186a972a09d2f22ff96a7bab621aa3 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 1 Jun 2016 16:29:17 +0200 Subject: [PATCH] fix(mpd): Avoid nullptrs --- include/interfaces/mpd.hpp | 6 +++--- src/interfaces/mpd.cpp | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/interfaces/mpd.hpp b/include/interfaces/mpd.hpp index c2f4a2d3..d6e45744 100644 --- a/include/interfaces/mpd.hpp +++ b/include/interfaces/mpd.hpp @@ -122,15 +122,15 @@ namespace mpd bool mpd_idle = false; int mpd_fd; - void check_connection() throw(ClientError); + void check_connection(); void check_prerequisites(); void check_prerequisites_commands_list(); - void check_errors() throw(ClientError, ServerError); + void check_errors(); public: static std::shared_ptr &get(); - void connect() throw (ClientError); + void connect(); void disconnect(); bool connected(); bool retry_connection(int interval = 1); diff --git a/src/interfaces/mpd.cpp b/src/interfaces/mpd.cpp index e8e41f29..e1530594 100644 --- a/src/interfaces/mpd.cpp +++ b/src/interfaces/mpd.cpp @@ -21,7 +21,7 @@ namespace mpd // Base - void Connection::connect() throw (ClientError) + void Connection::connect() { assert(!this->connection); @@ -40,7 +40,7 @@ namespace mpd this->check_errors(); } catch(ClientError &e) { this->disconnect(); - throw e; + throw &e; } } @@ -97,7 +97,7 @@ namespace mpd return flags; } - void Connection::check_connection() throw(ClientError) + void Connection::check_connection() { if (!this->connection) throw ClientError("Not connected to MPD server", MPD_ERROR_STATE, false); @@ -116,7 +116,7 @@ namespace mpd this->check_prerequisites(); } - void Connection::check_errors() throw(ClientError, ServerError) + void Connection::check_errors() { auto connection = this->connection.get(); mpd_error code = mpd_connection_get_error(connection); @@ -367,19 +367,28 @@ namespace mpd std::string Song::get_artist() { assert(this->song); - return mpd_song_get_tag(this->song.get(), MPD_TAG_ARTIST, 0); + auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_ARTIST, 0); + if (tag == nullptr) + return ""; + return std::string(tag); } std::string Song::get_album() { assert(this->song); - return mpd_song_get_tag(this->song.get(), MPD_TAG_ALBUM, 0); + auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_ALBUM, 0); + if (tag == nullptr) + return ""; + return std::string(tag); } std::string Song::get_title() { assert(this->song); - return mpd_song_get_tag(this->song.get(), MPD_TAG_TITLE, 0); + auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_TITLE, 0); + if (tag == nullptr) + return ""; + return std::string(tag); } unsigned Song::get_duration()