refactor: change type of linenr_T from long to int32_t

The size of long varies depending on architecture, in contrast to the
MAXLNUM constant which sets the maximum allowable number of lines to
2^32-1. This discrepancy may lead to hard to detect bugs, for example
https://github.com/neovim/neovim/issues/18454. Setting linenr_T to a
fix maximum size of 2^32-1 will prevent this type of errors in the
future.

Also change the variables `amount` and `amount_after` to be linenr_T
since they're referring to "the line number difference" between two
texts.
This commit is contained in:
Dundar Goc
2022-05-07 12:53:37 +02:00
parent e15d31b530
commit a732c253b7
30 changed files with 165 additions and 148 deletions

View File

@@ -272,7 +272,7 @@ int u_inssub(linenr_T lnum)
*/
int u_savedel(linenr_T lnum, long nlines)
{
return u_savecommon(curbuf, lnum - 1, lnum + nlines,
return u_savecommon(curbuf, lnum - 1, lnum + (linenr_T)nlines,
nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, false);
}
@@ -2337,7 +2337,7 @@ static void u_undoredo(int undo, bool do_buf_event)
}
oldsize = bot - top - 1; // number of lines before undo
newsize = uep->ue_size; // number of lines after undo
newsize = (linenr_T)uep->ue_size; // number of lines after undo
if (top < newlnum) {
/* If the saved cursor is somewhere in this undo block, move it to
@@ -2351,8 +2351,8 @@ static void u_undoredo(int undo, bool do_buf_event)
/* Use the first line that actually changed. Avoids that
* undoing auto-formatting puts the cursor in the previous
* line. */
for (i = 0; i < newsize && i < oldsize; ++i) {
if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0) {
for (i = 0; i < newsize && i < oldsize; i++) {
if (STRCMP(uep->ue_array[i], ml_get(top + 1 + (linenr_T)i)) != 0) {
break;
}
}
@@ -2360,7 +2360,7 @@ static void u_undoredo(int undo, bool do_buf_event)
newlnum = top;
curwin->w_cursor.lnum = newlnum + 1;
} else if (i < newsize) {
newlnum = top + i;
newlnum = top + (linenr_T)i;
curwin->w_cursor.lnum = newlnum + 1;
}
}
@@ -2405,8 +2405,7 @@ static void u_undoredo(int undo, bool do_buf_event)
// Adjust marks
if (oldsize != newsize) {
mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
(long)newsize - (long)oldsize, kExtmarkNOOP);
mark_adjust(top + 1, top + oldsize, MAXLNUM, newsize - oldsize, kExtmarkNOOP);
if (curbuf->b_op_start.lnum > top + oldsize) {
curbuf->b_op_start.lnum += newsize - oldsize;
}
@@ -2916,7 +2915,7 @@ static void u_getbot(buf_T *buf)
* old line count subtracted from the current line count.
*/
extra = buf->b_ml.ml_line_count - uep->ue_lcount;
uep->ue_bot = uep->ue_top + uep->ue_size + 1 + extra;
uep->ue_bot = uep->ue_top + (linenr_T)uep->ue_size + 1 + extra;
if (uep->ue_bot < 1 || uep->ue_bot > buf->b_ml.ml_line_count) {
iemsg(_("E440: undo line missing"));
uep->ue_bot = uep->ue_top + 1; // assume all lines deleted, will