From 0d339540daafdcd43c770b9b944844c5466e614b Mon Sep 17 00:00:00 2001 From: Thomas Jansen Date: Wed, 7 Oct 2009 23:33:34 +0200 Subject: [PATCH] lyrics: replaced asserts with error handler Handle missing artist and/or title for lyrics by defining an empty list of plugins that fails almost immediately. Note that args in lyrics_load may now start with NULL as the first array element. make_argv() in plugin.c made the assumption that at least one argument is passed. If the first argument is NULL a bogus pointer is returned by make_argv(). By converting do {} while into while {}, we allow the first argument to be NULL. --- src/lyrics.c | 8 +++++--- src/plugin.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lyrics.c b/src/lyrics.c index 43800eb..3f73690 100644 --- a/src/lyrics.c +++ b/src/lyrics.c @@ -22,16 +22,18 @@ #include -static struct plugin_list plugins; +static struct plugin_list empty, plugins; void lyrics_init(void) { + plugin_list_init(&empty); plugin_list_init(&plugins); plugin_list_load_directory(&plugins, LYRICS_PLUGIN_DIR); } void lyrics_deinit(void) { + plugin_list_deinit(&empty); plugin_list_deinit(&plugins); } @@ -41,8 +43,8 @@ lyrics_load(const char *artist, const char *title, { const char *args[3] = { artist, title, NULL }; - assert(artist != NULL); - assert(title != NULL); + if (artist == NULL || title == NULL) + return plugin_run(&empty, args, callback, data); return plugin_run(&plugins, args, callback, data); } diff --git a/src/plugin.c b/src/plugin.c index d784900..d89e210 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -340,9 +340,8 @@ make_argv(const char*const* args) /* reserve space for the program name */ *ret++ = NULL; - do { + while (*args != NULL) *ret++ = g_strdup(*args++); - } while (*args != NULL); /* end of argument vector */ *ret++ = NULL; -- 2.30.2