From b7d2d4cfe8b88174a7b1f41840ddc0b23dbd6a75 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 13 Sep 2011 21:36:51 +0200 Subject: [PATCH] database: don't allow uri==NULL Add nonnull attributes and fix all callers. --- src/command.c | 12 ++++++------ src/database.h | 5 +++++ src/dbUtils.h | 7 +++++-- src/db_print.c | 2 +- src/db_print.h | 8 ++++++++ src/locate.h | 8 ++++++++ src/stats.c | 2 +- 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/command.c b/src/command.c index ad13d75bc..13b3d4ca0 100644 --- a/src/command.c +++ b/src/command.c @@ -963,7 +963,7 @@ handle_find(struct client *client, int argc, char *argv[]) } GError *error = NULL; - enum command_return ret = findSongsIn(client, NULL, list, &error) + enum command_return ret = findSongsIn(client, "", list, &error) ? COMMAND_RETURN_OK : print_error(client, error); @@ -987,7 +987,7 @@ handle_findadd(struct client *client, int argc, char *argv[]) GError *error = NULL; enum command_return ret = - findAddIn(client->player_control, NULL, list, &error) + findAddIn(client->player_control, "", list, &error) ? COMMAND_RETURN_OK : print_error(client, error); @@ -1011,7 +1011,7 @@ handle_search(struct client *client, int argc, char *argv[]) } GError *error = NULL; - enum command_return ret = searchForSongsIn(client, NULL, list, &error) + enum command_return ret = searchForSongsIn(client, "", list, &error) ? COMMAND_RETURN_OK : print_error(client, error); @@ -1036,7 +1036,7 @@ handle_count(struct client *client, int argc, char *argv[]) GError *error = NULL; enum command_return ret = - searchStatsForSongsIn(client, NULL, list, &error) + searchStatsForSongsIn(client, "", list, &error) ? COMMAND_RETURN_OK : print_error(client, error); @@ -1266,7 +1266,7 @@ handle_prioid(struct client *client, int argc, char *argv[]) static enum command_return handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) { - char *directory = NULL; + const char *directory = ""; if (argc == 2) directory = argv[1]; @@ -1537,7 +1537,7 @@ handle_seekid(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) static enum command_return handle_listallinfo(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) { - char *directory = NULL; + const char *directory = ""; if (argc == 2) directory = argv[1]; diff --git a/src/database.h b/src/database.h index ab9114f2d..1696031d0 100644 --- a/src/database.h +++ b/src/database.h @@ -20,6 +20,8 @@ #ifndef MPD_DATABASE_H #define MPD_DATABASE_H +#include "gcc.h" + #include #include @@ -47,12 +49,15 @@ db_finish(void); struct directory * db_get_root(void); +gcc_nonnull(1) struct directory * db_get_directory(const char *name); +gcc_nonnull(1) struct song * db_get_song(const char *file); +gcc_nonnull(1,2) bool db_walk(const char *uri, const struct db_visitor *visitor, void *ctx, diff --git a/src/dbUtils.h b/src/dbUtils.h index f693a7793..40594652b 100644 --- a/src/dbUtils.h +++ b/src/dbUtils.h @@ -20,23 +20,26 @@ #ifndef MPD_DB_UTILS_H #define MPD_DB_UTILS_H +#include "gcc.h" + #include #include struct locate_item_list; struct player_control; +gcc_nonnull(1,2) bool addAllIn(struct player_control *pc, const char *uri, GError **error_r); +gcc_nonnull(1,2) bool addAllInToStoredPlaylist(const char *uri_utf8, const char *path_utf8, GError **error_r); +gcc_nonnull(1,2,3) bool findAddIn(struct player_control *pc, const char *name, const struct locate_item_list *criteria, GError **error_r); -unsigned long sumSongTimesIn(const char *name); - #endif diff --git a/src/db_print.c b/src/db_print.c index c4086a387..d398a22ac 100644 --- a/src/db_print.c +++ b/src/db_print.c @@ -286,7 +286,7 @@ listAllUniqueTags(struct client *client, int type, data.set = strset_new(); } - if (!db_walk(NULL, &unique_tags_visitor, &data, error_r)) { + if (!db_walk("", &unique_tags_visitor, &data, error_r)) { freeListCommandItem(item); return false; } diff --git a/src/db_print.h b/src/db_print.h index 7d6309517..76e43c3a0 100644 --- a/src/db_print.h +++ b/src/db_print.h @@ -20,6 +20,8 @@ #ifndef MPD_DB_PRINT_H #define MPD_DB_PRINT_H +#include "gcc.h" + #include #include @@ -27,28 +29,34 @@ struct client; struct locate_item_list; struct db_visitor; +gcc_nonnull(1,2) bool printAllIn(struct client *client, const char *uri_utf8, GError **error_r); +gcc_nonnull(1,2) bool printInfoForAllIn(struct client *client, const char *uri_utf8, GError **error_r); +gcc_nonnull(1,2,3) bool searchForSongsIn(struct client *client, const char *name, const struct locate_item_list *criteria, GError **error_r); +gcc_nonnull(1,2,3) bool findSongsIn(struct client *client, const char *name, const struct locate_item_list *criteria, GError **error_r); +gcc_nonnull(1,2,3) bool searchStatsForSongsIn(struct client *client, const char *name, const struct locate_item_list *criteria, GError **error_r); +gcc_nonnull(1,3) bool listAllUniqueTags(struct client *client, int type, const struct locate_item_list *criteria, diff --git a/src/locate.h b/src/locate.h index 6b544f243..ec20ded24 100644 --- a/src/locate.h +++ b/src/locate.h @@ -20,6 +20,8 @@ #ifndef MPD_LOCATE_H #define MPD_LOCATE_H +#include "gcc.h" + #include #include @@ -57,6 +59,7 @@ struct locate_item_list * locate_item_list_new(unsigned length); /* return number of items or -1 on error */ +gcc_nonnull(1) struct locate_item_list * locate_item_list_parse(char *argv[], int argc); @@ -64,19 +67,24 @@ locate_item_list_parse(char *argv[], int argc); * Duplicate the struct locate_item_list object and convert all * needles with g_utf8_casefold(). */ +gcc_nonnull(1) struct locate_item_list * locate_item_list_casefold(const struct locate_item_list *list); +gcc_nonnull(1) void locate_item_list_free(struct locate_item_list *list); +gcc_nonnull(1) void locate_item_free(struct locate_item *item); +gcc_nonnull(1,2) bool locate_song_search(const struct song *song, const struct locate_item_list *criteria); +gcc_nonnull(1,2) bool locate_song_match(const struct song *song, const struct locate_item_list *criteria); diff --git a/src/stats.c b/src/stats.c index fe0c2a476..ec39ff5b7 100644 --- a/src/stats.c +++ b/src/stats.c @@ -98,7 +98,7 @@ void stats_update(void) data.artists = strset_new(); data.albums = strset_new(); - db_walk(NULL, &collect_stats_visitor, &data, NULL); + db_walk("", &collect_stats_visitor, &data, NULL); stats.artist_count = strset_size(data.artists); stats.album_count = strset_size(data.albums);