diff options
Diffstat (limited to 'src/songvec.c')
-rw-r--r-- | src/songvec.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/songvec.c b/src/songvec.c index c15b99074..613c448cf 100644 --- a/src/songvec.c +++ b/src/songvec.c @@ -35,28 +35,29 @@ struct mpd_song *songvec_find(const struct songvec *sv, const char *url) int songvec_delete(struct songvec *sv, const struct mpd_song *del) { - int i; + size_t i; pthread_mutex_lock(&nr_lock); - for (i = sv->nr; --i >= 0; ) { + for (i = 0; i < sv->nr; ++i) { if (sv->base[i] != del) continue; /* we _don't_ call song_free() here */ if (!--sv->nr) { - pthread_mutex_unlock(&nr_lock); free(sv->base); sv->base = NULL; - return i; } else { - memmove(&sv->base[i], &sv->base[i + 1], - (sv->nr - i + 1) * sizeof(struct mpd_song *)); + if (i < sv->nr) + memmove(&sv->base[i], &sv->base[i + 1], + (sv->nr - i) * + sizeof(struct mpd_song *)); sv->base = xrealloc(sv->base, sv_size(sv)); } - break; + pthread_mutex_unlock(&nr_lock); + return i; } pthread_mutex_unlock(&nr_lock); - return i; + return -1; /* not found */ } void songvec_add(struct songvec *sv, struct mpd_song *add) |