diff options
Diffstat (limited to 'src/dirvec.c')
-rw-r--r-- | src/dirvec.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/dirvec.c b/src/dirvec.c index 14534d05e..cb695ac5d 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -36,28 +36,29 @@ 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; pthread_mutex_lock(&nr_lock); - 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 */ if (!--dv->nr) { - pthread_mutex_unlock(&nr_lock); free(dv->base); dv->base = NULL; - return i; } else { - memmove(&dv->base[i], &dv->base[i + 1], - (dv->nr - i + 1) * sizeof(struct directory *)); + if (i < dv->nr) + memmove(&dv->base[i], &dv->base[i + 1], + (dv->nr - i) * + sizeof(struct directory *)); dv->base = xrealloc(dv->base, dv_size(dv)); } - break; + pthread_mutex_unlock(&nr_lock); + return i; } pthread_mutex_unlock(&nr_lock); - return i; + return -1; /* not found */ } void dirvec_add(struct dirvec *dv, struct directory *add) |