aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fold.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/fold.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/fold.c')
-rw-r--r--src/nvim/fold.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index d5277b9910..93ad2a6926 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1370,7 +1370,8 @@ void deleteFoldRecurse(buf_T *bp, garray_T *gap)
// foldMarkAdjust() {{{2
/// Update line numbers of folds for inserted/deleted lines.
-void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long amount_after)
+void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, linenr_T amount,
+ linenr_T amount_after)
{
// If deleting marks from line1 to line2, but not deleting all those
// lines, set line2 so that only deleted lines have their folds removed.
@@ -1387,7 +1388,7 @@ void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long
// foldMarkAdjustRecurse() {{{2
static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, linenr_T line2,
- long amount, long amount_after)
+ linenr_T amount, linenr_T amount_after)
{
fold_T *fp;
linenr_T last;
@@ -2886,7 +2887,7 @@ static void foldMerge(win_T *const wp, fold_T *fp1, garray_T *gap, fold_T *fp2)
// If the last nested fold in fp1 touches the first nested fold in fp2,
// merge them recursively.
- if (foldFind(gap1, fp1->fd_len - 1L, &fp3) && foldFind(gap2, 0L, &fp4)) {
+ if (foldFind(gap1, fp1->fd_len - 1, &fp3) && foldFind(gap2, 0L, &fp4)) {
foldMerge(wp, fp3, gap2, fp4);
}
@@ -3256,7 +3257,7 @@ static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off
/// @return FAIL when writing failed.
static int put_fold_open_close(FILE *fd, fold_T *fp, linenr_T off)
{
- if (fprintf(fd, "%" PRId64, (int64_t)(fp->fd_top + off)) < 0
+ if (fprintf(fd, "%" PRIdLINENR, fp->fd_top + off) < 0
|| put_eol(fd) == FAIL
|| fprintf(fd, "normal! z%c",
fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0