# HG changeset patch # User ib # Date 1353846242 0 # Node ID e900dc6b8d6603869bf9bc130e870bdff6554c0a # Parent 6e07bbde3e46dfeea893f9c79c5fd643fe95b0af Improve add_to_gui_playlist(). Use pointer arithmetic rather than strlen() and rename variables. Moreover, a non-existing path (although not supposed to happen) shouldn't be an empty string. diff -r 6e07bbde3e46 -r e900dc6b8d66 gui/util/list.c --- a/gui/util/list.c Sun Nov 25 11:55:07 2012 +0000 +++ b/gui/util/list.c Sun Nov 25 12:24:02 2012 +0000 @@ -289,29 +289,30 @@ */ int add_to_gui_playlist(const char *what, int how) { - char *filename, *pathname; + const char *file; + char *path; plItem *item; if (!what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT)) return 0; - filename = strdup(mp_basename(what)); - pathname = strdup(what); + file = mp_basename(what); + path = strdup(what); - if (strlen(pathname) - strlen(filename) > 0) - pathname[strlen(pathname) - strlen(filename) - 1] = 0; // we have some path, so remove / at end + if (file > what) + path[file - what - 1] = 0; else - pathname[strlen(pathname) - strlen(filename)] = 0; + strcpy(path, "."); item = calloc(1, sizeof(plItem)); if (!item) return 0; - mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", pathname, filename); + mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", path, file); - item->name = filename; - item->path = pathname; + item->name = strdup(file); + item->path = path; listMgr(how, item);