fix(decoration): fix crash when on_lines decor provider modifies marktree

If a "on_lines" callback changes the structure of the marktree, the
iterator (which is used for an entire window viewport) might now
point to invalid memory. Restore the iterator to the beginning of the
line in this case.

fixes #29484
This commit is contained in:
bfredl
2025-01-03 12:36:36 +01:00
parent fa298fd2f4
commit 33ff546b50
6 changed files with 55 additions and 7 deletions

View File

@@ -95,6 +95,7 @@ void extmark_set(buf_T *buf, uint32_t ns_id, uint32_t *idp, int row, colnr_T col
MTKey mark = { { row, col }, ns_id, id, flags, decor.data };
marktree_put(buf->b_marktree, mark, end_row, end_col, end_right_gravity);
decor_state_invalidate(buf);
revised:
if (decor_flags || decor.ext) {
@@ -184,6 +185,8 @@ void extmark_del(buf_T *buf, MarkTreeIter *itr, MTKey key, bool restore)
}
}
decor_state_invalidate(buf);
// TODO(bfredl): delete it from current undo header, opportunistically?
}
@@ -237,6 +240,10 @@ bool extmark_clear(buf_T *buf, uint32_t ns_id, int l_row, colnr_T l_col, int u_r
}
}
if (marks_cleared_any) {
decor_state_invalidate(buf);
}
return marks_cleared_any;
}