From 0d34815f6cfe1a75467e7c8f9406ff15bcbe10ba Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 7 Oct 2008 21:20:34 +0200 Subject: Assert if we don't have song or song->url set song objects cannot exist without a path or URL --- src/directory.c | 4 ++-- src/song.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/directory.c b/src/directory.c index 8eb18d463..e38a904f0 100644 --- a/src/directory.c +++ b/src/directory.c @@ -298,8 +298,8 @@ removeDeletedFromDirectory(char *path_max_tmp, Directory * directory) for (i = sv->nr; --i >= 0; ) { /* cleaner deletes if we go backwards */ Song *song = sv->base[i]; - if (!song || !*song->url) - continue; /* does this happen?, perhaps assert() */ + assert(song); + assert(*song->url); if (dirname) sprintf(path_max_tmp, "%s/%s", dirname, song->url); diff --git a/src/song.c b/src/song.c index 54e9ea7e0..acc19eb0e 100644 --- a/src/song.c +++ b/src/song.c @@ -31,8 +31,13 @@ Song * song_alloc(const char *url, struct _Directory *parent) { - size_t urllen = strlen(url); - Song *song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1); + size_t urllen; + Song *song; + + assert(url); + urllen = strlen(url); + assert(urllen); + song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1); song->tag = NULL; memcpy(song->url, url, urllen + 1); @@ -44,6 +49,7 @@ song_alloc(const char *url, struct _Directory *parent) Song *newSong(const char *url, Directory * parentDir) { Song *song; + assert(*url); if (strchr(url, '\n')) { DEBUG("newSong: '%s' is not a valid uri\n", url); -- cgit v1.2.3