aboutsummaryrefslogtreecommitdiffstats
path: root/src/dirvec.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-14 11:10:00 +0200
committerMax Kellermann <max@duempel.org>2008-10-14 11:10:00 +0200
commit06c8a9ed0b1a01343d21859bff22ae67f4b29021 (patch)
treeef6fb6b9d77f6d83bd0ef35d176f5475bb218550 /src/dirvec.c
parentf71ac4d479502738682f2328a6523d18be705ac9 (diff)
downloadmpd-06c8a9ed0b1a01343d21859bff22ae67f4b29021.tar.gz
mpd-06c8a9ed0b1a01343d21859bff22ae67f4b29021.tar.xz
mpd-06c8a9ed0b1a01343d21859bff22ae67f4b29021.zip
{dir,song}vec: fix off-by-one errors in {dir,song}vec_delete
Found by Valgrind while looking for another bug... Hmm.. I should really just make this code generic since they're duplicated...
Diffstat (limited to 'src/dirvec.c')
-rw-r--r--src/dirvec.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/dirvec.c b/src/dirvec.c
index 72b1c0084..98cb9e7ad 100644
--- a/src/dirvec.c
+++ b/src/dirvec.c
@@ -37,9 +37,9 @@ struct directory *dirvec_find(const struct dirvec *dv, const char *path)
int dirvec_delete(struct dirvec *dv, struct directory *del)
{
- int i;
+ size_t i;
- for (i = dv->nr; --i >= 0; ) {
+ for (i = 0; i < dv->nr; ++i) {
if (dv->base[i] != del)
continue;
/* we _don't_ call directory_free() here */
@@ -48,7 +48,7 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
dv->base = NULL;
} else {
memmove(&dv->base[i], &dv->base[i + 1],
- (dv->nr - i + 1) * sizeof(struct directory *));
+ (dv->nr - i) * sizeof(struct directory *));
dv->base = xrealloc(dv->base, dv_size(dv));
}
return i;