must use safe iteration over file index entries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/lib/fileindex.c b/lib/fileindex.c
index dbe625f..05a75f2 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -121,14 +121,14 @@ got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path)
}
const struct got_error *
-got_fileindex_for_each_entry(struct got_fileindex *fileindex,
+got_fileindex_for_each_entry_safe(struct got_fileindex *fileindex,
const struct got_error *(cb)(void *, struct got_fileindex_entry *),
void *cb_arg)
{
const struct got_error *err = NULL;
- struct got_fileindex_entry *entry;
+ struct got_fileindex_entry *entry, *tmp;
- TAILQ_FOREACH(entry, &fileindex->entries, entry) {
+ TAILQ_FOREACH_SAFE(entry, &fileindex->entries, entry, tmp) {
err = cb(cb_arg, entry);
if (err)
break;
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index f93174f..327aba8 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -100,5 +100,6 @@ void got_fileindex_entry_remove(struct got_fileindex *,
struct got_fileindex_entry *got_fileindex_entry_get(struct got_fileindex *,
const char *);
const struct got_error *got_fileindex_read(struct got_fileindex *, FILE *);
-const struct got_error *got_fileindex_for_each_entry(struct got_fileindex *,
+const struct got_error *got_fileindex_for_each_entry_safe(
+ struct got_fileindex *,
const struct got_error *(cb)(void *, struct got_fileindex_entry *), void *);
diff --git a/lib/worktree.c b/lib/worktree.c
index 68c4f29..e43e15f 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -800,7 +800,8 @@ remove_missing_files(struct got_worktree *worktree, const char *path,
a.missing_entries.nentries = 0;
a.current_subdir = apply_path_prefix(worktree, path);
TAILQ_INIT(&a.missing_entries.entries);
- err = got_fileindex_for_each_entry(fileindex, collect_missing_file, &a);
+ err = got_fileindex_for_each_entry_safe(fileindex,
+ collect_missing_file, &a);
if (err)
return err;