vim-patch:8.2.0853: ml_delete() often called with FALSE argument

Problem:    ml_delete() often called with FALSE argument.
Solution:   Use ml_delete_flags(x, ML_DEL_MESSAGE) when argument is TRUE.

ca70c07b72

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
Jan Edmund Lazo
2025-08-18 20:37:33 -04:00
committed by zeertzjq
parent c8912d7329
commit 9b5545103e
13 changed files with 27 additions and 29 deletions

View File

@@ -158,12 +158,12 @@ static int read_buffer(bool read_stdin, exarg_T *eap, int flags)
if (retval == OK) {
// Delete the binary lines.
while (--line_count >= 0) {
ml_delete(1, false);
ml_delete(1);
}
} else {
// Delete the converted lines.
while (curbuf->b_ml.ml_line_count > line_count) {
ml_delete(line_count, false);
ml_delete(line_count);
}
}
// Put the cursor on the first line.
@@ -759,7 +759,7 @@ void buf_clear(void)
linenr_T line_count = curbuf->b_ml.ml_line_count;
extmark_free_all(curbuf); // delete any extmarks
while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(1, false);
ml_delete(1);
}
deleted_lines_mark(1, line_count); // prepare for display
}

View File

@@ -1981,7 +1981,7 @@ void del_lines(linenr_T nlines, bool undo)
break;
}
ml_delete(first, true);
ml_delete_flags(first, ML_DEL_MESSAGE);
n++;
// If we delete the last line in the file, stop

View File

@@ -3075,7 +3075,7 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
for (int i = 0; i < count; i++) {
// remember deleting the last line of the buffer
buf_empty = curbuf->b_ml.ml_line_count == 1;
if (ml_delete(lnum, false) == OK) {
if (ml_delete(lnum) == OK) {
added--;
}
}
@@ -3096,7 +3096,7 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
// which results in inaccurate reporting of the byte count of
// previous contents in buffer-update events.
buf_empty = false;
ml_delete(2, false);
ml_delete(2);
}
}
linenr_T new_count = dp->df_count[idx_to] + added;

View File

@@ -454,7 +454,7 @@ void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
for (linenr_T lnum = first; lnum <= last; lnum++) {
ml_delete(first, true);
ml_delete_flags(first, ML_DEL_MESSAGE);
}
FOR_ALL_TAB_WINDOWS(tp, wp) {

View File

@@ -659,7 +659,7 @@ void ex_sort(exarg_T *eap)
// delete the original lines if appending worked
if (i == count) {
for (i = 0; i < count; i++) {
ml_delete(eap->line1, false);
ml_delete(eap->line1);
}
} else {
count = 0;
@@ -806,7 +806,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
}
for (l = line1; l <= line2; l++) {
ml_delete(line1 + extra, true);
ml_delete_flags(line1 + extra, ML_DEL_MESSAGE);
}
if (!global_busy && num_lines > p_report) {
smsg(0, NGETTEXT("%" PRId64 " line moved",
@@ -2867,7 +2867,7 @@ void ex_append(exarg_T *eap)
lnum++;
if (empty) {
ml_delete(2, false);
ml_delete(2);
empty = false;
}
}
@@ -2917,7 +2917,7 @@ void ex_change(exarg_T *eap)
if (curbuf->b_ml.ml_flags & ML_EMPTY) { // nothing to delete
break;
}
ml_delete(eap->line1, false);
ml_delete(eap->line1);
}
// make sure the cursor is not beyond the end of the file now
@@ -4107,7 +4107,7 @@ skip:
break;
}
for (i = 0; i < nmatch_tl; i++) {
ml_delete(lnum, false);
ml_delete(lnum);
}
mark_adjust(lnum, lnum + nmatch_tl - 1, MAXLNUM, -nmatch_tl, kExtmarkNOOP);
if (subflags.do_ask) {

View File

@@ -5934,7 +5934,7 @@ static void ex_read(exarg_T *eap)
lnum = 1;
}
if (*ml_get(lnum) == NUL && u_savedel(lnum, 1) == OK) {
ml_delete(lnum, false);
ml_delete(lnum);
if (curwin->w_cursor.lnum > 1
&& curwin->w_cursor.lnum >= lnum) {
curwin->w_cursor.lnum--;

View File

@@ -733,7 +733,7 @@ retry:
}
// Delete the previously read lines.
while (lnum > from) {
ml_delete(lnum--, false);
ml_delete(lnum--);
}
file_rewind = false;
if (set_options) {
@@ -1660,7 +1660,7 @@ failed:
if (!recoverymode) {
// need to delete the last line, which comes from the empty buffer
if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(curbuf->b_ml.ml_line_count, false);
ml_delete(curbuf->b_ml.ml_line_count);
linecnt--;
}
curbuf->deleted_bytes = 0;
@@ -2836,7 +2836,7 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
if (retval != FAIL) {
curbuf = frombuf;
for (linenr_T lnum = curbuf->b_ml.ml_line_count; lnum > 0; lnum--) {
if (ml_delete(lnum, false) == FAIL) {
if (ml_delete(lnum) == FAIL) {
// Oops! We could try putting back the saved lines, but that
// might fail again...
retval = FAIL;
@@ -3152,7 +3152,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
// Put the text back from the save buffer. First
// delete any lines that readfile() added.
while (!buf_is_empty(curbuf)) {
if (ml_delete(buf->b_ml.ml_line_count, false) == FAIL) {
if (ml_delete(buf->b_ml.ml_line_count) == FAIL) {
break;
}
}

View File

@@ -3809,7 +3809,7 @@ void ins_compl_delete(bool new_leader)
}
while (curwin->w_cursor.lnum > compl_lnum) {
if (ml_delete(curwin->w_cursor.lnum, false) == FAIL) {
if (ml_delete(curwin->w_cursor.lnum) == FAIL) {
if (remaining.data) {
xfree(remaining.data);
}

View File

@@ -961,7 +961,7 @@ void ml_recover(bool checkext)
// Now that we are sure that the file is going to be recovered, clear the
// contents of the current buffer.
while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(1, false);
ml_delete(1);
}
// Try reading the original file to obtain the values of 'fileformat',
@@ -1185,7 +1185,7 @@ void ml_recover(bool checkext)
// empty buffer. These will now be after the last line in the buffer.
while (curbuf->b_ml.ml_line_count > lnum
&& !(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(curbuf->b_ml.ml_line_count, false);
ml_delete(curbuf->b_ml.ml_line_count);
}
curbuf->b_flags |= BF_RECOVERED;
check_cursor(curwin);
@@ -2690,12 +2690,10 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, int flags)
/// @note The caller of this function should probably also call
/// deleted_lines() after this.
///
/// @param message true may give a "No lines in buffer" message.
///
/// @return FAIL for failure, OK otherwise
int ml_delete(linenr_T lnum, bool message)
int ml_delete(linenr_T lnum)
{
return ml_delete_flags(lnum, message ? ML_DEL_MESSAGE : 0);
return ml_delete_flags(lnum, 0);
}
/// Like ml_delete() but using flags (see ml_delete_int()).

View File

@@ -6598,7 +6598,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// When all lines were selected and deleted do_put() leaves an empty
// line that needs to be deleted now.
if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) {
ml_delete(curbuf->b_ml.ml_line_count, true);
ml_delete_flags(curbuf->b_ml.ml_line_count, ML_DEL_MESSAGE);
deleted_lines(curbuf->b_ml.ml_line_count + 1, 1);
// If the cursor was in that line, move it to the end of the last

View File

@@ -4180,7 +4180,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q
while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) {
// If deletion fails, this loop may run forever, so
// signal error and return.
if (ml_delete(1, false) == FAIL) {
if (ml_delete(1) == FAIL) {
internal_error("qf_fill_buffer()");
return;
}
@@ -4250,7 +4250,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q
}
if (old_last == NULL) {
// Delete the empty line which is now at the end
ml_delete(lnum + 1, false);
ml_delete(lnum + 1);
}
qfga_clear();

View File

@@ -3234,7 +3234,7 @@ void ex_spelldump(exarg_T *eap)
// Delete the empty line that we started with.
if (curbuf->b_ml.ml_line_count > 1) {
ml_delete(curbuf->b_ml.ml_line_count, false);
ml_delete(curbuf->b_ml.ml_line_count);
}
redraw_later(curwin, UPD_NOT_VALID);
}

View File

@@ -2132,7 +2132,7 @@ static void adjust_scrollback(Terminal *term, buf_T *buf)
if (scbk < term->sb_current) {
size_t diff = term->sb_current - scbk;
for (size_t i = 0; i < diff; i++) {
ml_delete(1, false);
ml_delete(1);
term->sb_current--;
xfree(term->sb_buffer[term->sb_current]);
}