From: Thomas Jansen Date: Wed, 7 Oct 2009 21:33:34 +0000 (+0200) Subject: lyrics: replaced asserts with error handler X-Git-Tag: release-0.16~161 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0d339540daafdcd43c770b9b944844c5466e614b;p=ncmpc.git 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. --- 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;