vim-patch:8.2.0109: corrupted text properties when expanding spaces

Problem:    Corrupted text properties when expanding spaces.
Solution:   Reallocate the line. (Nobuhiro Takasaki, closes vim/vim#5457)

ac15fd8c67

Co-authored-by: Bram Moolenaar <Bram@vim.org>
(cherry picked from commit 97d9d71bf3)
This commit is contained in:
zeertzjq
2024-06-02 15:00:16 +08:00
committed by github-actions[bot]
parent 704d33634e
commit 571e54e12c

View File

@ -4420,9 +4420,18 @@ static bool ins_tab(void)
int i = cursor->col - fpos.col;
if (i > 0) {
if (!(State & VREPLACE_FLAG)) {
memmove(ptr, ptr + i, (size_t)(curbuf->b_ml.ml_line_len - i
- (ptr - curbuf->b_ml.ml_line_ptr)));
char *newp = xmalloc((size_t)(curbuf->b_ml.ml_line_len - i));
ptrdiff_t col = ptr - curbuf->b_ml.ml_line_ptr;
if (col > 0) {
memmove(newp, ptr - col, (size_t)col);
}
memmove(newp + col, ptr + i, (size_t)(curbuf->b_ml.ml_line_len - col - i));
if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) {
xfree(curbuf->b_ml.ml_line_ptr);
}
curbuf->b_ml.ml_line_ptr = newp;
curbuf->b_ml.ml_line_len -= i;
curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
inserted_bytes(fpos.lnum, change_col,
cursor->col - change_col, fpos.col - change_col);
} else {