aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mark.c
diff options
context:
space:
mode:
authorDundar Goc <gocdundar@gmail.com>2022-05-07 12:53:37 +0200
committerDundar Goc <gocdundar@gmail.com>2022-06-10 16:16:41 +0200
commita732c253b71f89702285d5ec6fd7803045f6add9 (patch)
treecd6b0dbad292dcbfaae637ffad385298594a2ff2 /src/nvim/mark.c
parente15d31b530c443daea04d7a772b24da737397c53 (diff)
downloadrneovim-a732c253b71f89702285d5ec6fd7803045f6add9.tar.gz
rneovim-a732c253b71f89702285d5ec6fd7803045f6add9.tar.bz2
rneovim-a732c253b71f89702285d5ec6fd7803045f6add9.zip
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.
Diffstat (limited to 'src/nvim/mark.c')
-rw-r--r--src/nvim/mark.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 35000ce39a..7b7441ebcf 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -732,7 +732,7 @@ static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int cu
}
msg_putchar('\n');
if (!got_int) {
- snprintf((char *)IObuff, IOSIZE, " %c %6ld %4d ", c, p->lnum, p->col);
+ snprintf((char *)IObuff, IOSIZE, " %c %6" PRIdLINENR " %4d ", c, p->lnum, p->col);
msg_outtrans(IObuff);
if (name != NULL) {
msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0);
@@ -860,12 +860,10 @@ void ex_jumps(exarg_T *eap)
xfree(name);
break;
}
- sprintf((char *)IObuff, "%c %2d %5ld %4d ",
- i == curwin->w_jumplistidx ? '>' : ' ',
- i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
- : curwin->w_jumplistidx - i,
- curwin->w_jumplist[i].fmark.mark.lnum,
- curwin->w_jumplist[i].fmark.mark.col);
+ snprintf((char *)IObuff, IOSIZE, "%c %2d %5" PRIdLINENR " %4d ",
+ i == curwin->w_jumplistidx ? '>' : ' ',
+ i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx : curwin->w_jumplistidx - i,
+ curwin->w_jumplist[i].fmark.mark.lnum, curwin->w_jumplist[i].fmark.mark.col);
msg_outtrans(IObuff);
msg_outtrans_attr(name,
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
@@ -963,7 +961,8 @@ void ex_changes(exarg_T *eap)
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
* or: mark_adjust(56, 55, MAXLNUM, 2);
*/
-void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after, ExtmarkOp op)
+void mark_adjust(linenr_T line1, linenr_T line2, linenr_T amount, linenr_T amount_after,
+ ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, true, op);
}
@@ -973,14 +972,14 @@ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after,
// This is only useful when folds need to be moved in a way different to
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
// for an example of why this may be necessary, see do_move().
-void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount, long amount_after,
+void mark_adjust_nofold(linenr_T line1, linenr_T line2, linenr_T amount, linenr_T amount_after,
ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, false, op);
}
-static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, long amount_after,
- bool adjust_folds, ExtmarkOp op)
+static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount,
+ linenr_T amount_after, bool adjust_folds, ExtmarkOp op)
{
int i;
int fnum = curbuf->b_fnum;
@@ -1153,7 +1152,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo
// position.
// "spaces_removed" is the number of spaces that were removed, matters when the
// cursor is inside them.
-void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount,
+void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long col_amount,
int spaces_removed)
{
int i;