diff options
author | Max Kellermann <max@duempel.org> | 2012-08-22 21:40:20 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-08-22 21:40:20 +0200 |
commit | e8df7e8da5a075178224b130c0602b62c85508a9 (patch) | |
tree | 76d57e65c2094d98909ff2ada88abc717e5422f9 /src/DatabasePrint.cxx | |
parent | af4252bc8043487a47a42a07326caf44bc78714f (diff) | |
download | mpd-e8df7e8da5a075178224b130c0602b62c85508a9.tar.gz mpd-e8df7e8da5a075178224b130c0602b62c85508a9.tar.xz mpd-e8df7e8da5a075178224b130c0602b62c85508a9.zip |
Database*: fix nullptr dereference when no database is configured
Diffstat (limited to '')
-rw-r--r-- | src/DatabasePrint.cxx | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx index b58619a95..621679729 100644 --- a/src/DatabasePrint.cxx +++ b/src/DatabasePrint.cxx @@ -115,6 +115,10 @@ bool db_selection_print(struct client *client, const DatabaseSelection &selection, bool full, GError **error_r) { + const Database *db = GetDatabase(error_r); + if (db == nullptr) + return false; + using namespace std::placeholders; const auto d = selection.match == nullptr ? std::bind(PrintDirectory, client, _1) @@ -126,7 +130,7 @@ db_selection_print(struct client *client, const DatabaseSelection &selection, client, _1, _2) : VisitPlaylist(); - return GetDatabase()->Visit(selection, d, s, p, error_r); + return db->Visit(selection, d, s, p, error_r); } struct SearchStats { @@ -154,6 +158,10 @@ searchStatsForSongsIn(struct client *client, const char *name, const struct locate_item_list *criteria, GError **error_r) { + const Database *db = GetDatabase(error_r); + if (db == nullptr) + return false; + const DatabaseSelection selection(name, true, criteria); SearchStats stats; @@ -163,7 +171,7 @@ searchStatsForSongsIn(struct client *client, const char *name, using namespace std::placeholders; const auto f = std::bind(stats_visitor_song, std::ref(stats), _1); - if (!GetDatabase()->Visit(selection, f, error_r)) + if (!db->Visit(selection, f, error_r)) return false; printSearchStats(client, &stats); @@ -206,18 +214,21 @@ listAllUniqueTags(struct client *client, int type, const struct locate_item_list *criteria, GError **error_r) { + const Database *db = GetDatabase(error_r); + if (db == nullptr) + return false; + const DatabaseSelection selection("", true, criteria); if (type == LOCATE_TAG_FILE_TYPE) { using namespace std::placeholders; const auto f = std::bind(PrintSongURIVisitor, client, _1); - return GetDatabase()->Visit(selection, f, error_r); + return db->Visit(selection, f, error_r); } else { using namespace std::placeholders; const auto f = std::bind(PrintUniqueTag, client, (enum tag_type)type, _1); - return GetDatabase()->VisitUniqueTags(selection, - (enum tag_type)type, - f, error_r); + return db->VisitUniqueTags(selection, (enum tag_type)type, + f, error_r); } } |