aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/nvim/api/buffer.c17
-rw-r--r--src/nvim/api/private/helpers.c7
-rw-r--r--src/nvim/api/vimscript.c4
-rw-r--r--src/nvim/api/win_config.c2
-rw-r--r--src/nvim/change.c22
-rw-r--r--src/nvim/charset.c16
-rw-r--r--src/nvim/debugger.c2
-rw-r--r--src/nvim/diff.c50
-rw-r--r--src/nvim/edit.c4
-rw-r--r--src/nvim/ex_cmds.c6
-rw-r--r--src/nvim/ex_docmd.c16
-rw-r--r--src/nvim/extmark.c4
-rw-r--r--src/nvim/fold.c9
-rw-r--r--src/nvim/lua/stdlib.c2
-rw-r--r--src/nvim/mark.c23
-rw-r--r--src/nvim/match.c4
-rw-r--r--src/nvim/move.c10
-rw-r--r--src/nvim/normal.c28
-rw-r--r--src/nvim/ops.c20
-rw-r--r--src/nvim/popupmnu.c2
-rw-r--r--src/nvim/pos.h6
-rw-r--r--src/nvim/quickfix.c25
-rw-r--r--src/nvim/search.c2
-rw-r--r--src/nvim/shada.c9
-rw-r--r--src/nvim/sign.c2
-rw-r--r--src/nvim/tag.c2
-rw-r--r--src/nvim/terminal.c2
-rw-r--r--src/nvim/undo.c15
28 files changed, 163 insertions, 148 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 4fa8b13c54..536be1d832 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -420,7 +420,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
goto end;
}
- bcount_t deleted_bytes = get_region_bytecount(curbuf, start, end, 0, 0);
+ bcount_t deleted_bytes = get_region_bytecount(curbuf, (linenr_T)start, (linenr_T)end, 0, 0);
// If the size of the range is reducing (ie, new_len < old_len) we
// need to delete some old_len. We do this at the start, by
@@ -490,14 +490,14 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ
mark_adjust((linenr_T)start,
(linenr_T)(end - 1),
MAXLNUM,
- (long)extra,
+ (linenr_T)extra,
kExtmarkNOOP);
extmark_splice(curbuf, (int)start - 1, 0, (int)(end - start), 0,
deleted_bytes, (int)new_len, 0, inserted_bytes,
kExtmarkUndo);
- changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true);
+ changed_lines((linenr_T)start, 0, (linenr_T)end, (linenr_T)extra, true);
fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra);
end:
@@ -564,13 +564,13 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
return;
}
- char *str_at_start = (char *)ml_get_buf(buf, start_row, false);
+ char *str_at_start = (char *)ml_get_buf(buf, (linenr_T)start_row, false);
if (start_col < 0 || (size_t)start_col > strlen(str_at_start)) {
api_set_error(err, kErrorTypeValidation, "start_col out of bounds");
return;
}
- char *str_at_end = (char *)ml_get_buf(buf, end_row, false);
+ char *str_at_end = (char *)ml_get_buf(buf, (linenr_T)end_row, false);
size_t len_at_end = strlen(str_at_end);
if (end_col < 0 || (size_t)end_col > len_at_end) {
api_set_error(err, kErrorTypeValidation, "end_col out of bounds");
@@ -600,7 +600,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
for (int64_t i = 1; i < end_row - start_row; i++) {
int64_t lnum = start_row + i;
- const char *bufline = (char *)ml_get_buf(buf, lnum, false);
+ const char *bufline = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
old_byte += (bcount_t)(strlen(bufline)) + 1;
}
old_byte += (bcount_t)end_col + 1;
@@ -725,7 +725,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
mark_adjust((linenr_T)start_row,
(linenr_T)end_row,
MAXLNUM,
- (long)extra,
+ (linenr_T)extra,
kExtmarkNOOP);
colnr_T col_extent = (colnr_T)(end_col
@@ -735,8 +735,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
(int)new_len - 1, (colnr_T)last_item.size, new_byte,
kExtmarkUndo);
- changed_lines((linenr_T)start_row, 0, (linenr_T)end_row + 1,
- (long)extra, true);
+ changed_lines((linenr_T)start_row, 0, (linenr_T)end_row + 1, (linenr_T)extra, true);
// adjust cursor like an extmark ( i e it was inside last_part_len)
if (curwin->w_cursor.lnum == end_row && curwin->w_cursor.col > end_col) {
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index af4aaf01aa..1ddaf63743 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -1397,7 +1397,8 @@ bool set_mark(buf_T *buf, String name, Integer line, Integer col, Error *err)
return res;
}
}
- pos_T pos = { line, (int)col, (int)col };
+ assert(INT32_MIN <= line && line <= INT32_MAX);
+ pos_T pos = { (linenr_T)line, (int)col, (int)col };
res = setmark_pos(*name.data, &pos, buf->handle);
if (!res) {
if (deleting) {
@@ -1773,9 +1774,9 @@ void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdinfo, cha
// Command range / count.
if (eap->argt & EX_RANGE) {
if (eap->addr_count == 1) {
- kv_printf(cmdline, "%ld", eap->line2);
+ kv_printf(cmdline, "%" PRIdLINENR, eap->line2);
} else if (eap->addr_count > 1) {
- kv_printf(cmdline, "%ld,%ld", eap->line1, eap->line2);
+ kv_printf(cmdline, "%" PRIdLINENR ",%" PRIdLINENR, eap->line1, eap->line2);
eap->addr_count = 2; // Make sure address count is not greater than 2
}
}
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c
index 4b4404ea09..6d0b9c7d99 100644
--- a/src/nvim/api/vimscript.c
+++ b/src/nvim/api/vimscript.c
@@ -1155,8 +1155,8 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
}
if (range.size > 0) {
- ea.line1 = range.items[0].data.integer;
- ea.line2 = range.items[range.size - 1].data.integer;
+ ea.line1 = (linenr_T)range.items[0].data.integer;
+ ea.line2 = (linenr_T)range.items[range.size - 1].data.integer;
}
if (invalid_range(&ea) != NULL) {
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index 898d95f49a..969643eeef 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -325,7 +325,7 @@ static bool parse_float_bufpos(Array bufpos, lpos_T *out)
|| bufpos.items[1].type != kObjectTypeInteger) {
return false;
}
- out->lnum = bufpos.items[0].data.integer;
+ out->lnum = (linenr_T)bufpos.items[0].data.integer;
out->col = (colnr_T)bufpos.items[1].data.integer;
return true;
}
diff --git a/src/nvim/change.c b/src/nvim/change.c
index fa1de69e2c..21afbf66de 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -138,7 +138,7 @@ void changed_internal(void)
/// Common code for when a change was made.
/// See changed_lines() for the arguments.
/// Careful: may trigger autocommands that reload the buffer.
-static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
+static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra)
{
// mark the buffer as modified
changed();
@@ -349,7 +349,7 @@ static void changedOneline(buf_T *buf, linenr_T lnum)
void changed_bytes(linenr_T lnum, colnr_T col)
{
changedOneline(curbuf, lnum);
- changed_common(lnum, col, lnum + 1, 0L);
+ changed_common(lnum, col, lnum + 1, 0);
// notify any channels that are watching
buf_updates_send_changes(curbuf, lnum, 1, 1);
@@ -382,7 +382,7 @@ void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new)
/// Appended "count" lines below line "lnum" in the current buffer.
/// Must be called AFTER the change and after mark_adjust().
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
-void appended_lines(linenr_T lnum, long count)
+void appended_lines(linenr_T lnum, linenr_T count)
{
changed_lines(lnum + 1, 0, lnum + 1, count, true);
}
@@ -393,18 +393,18 @@ void appended_lines_mark(linenr_T lnum, long count)
// Skip mark_adjust when adding a line after the last one, there can't
// be marks there. But it's still needed in diff mode.
if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) {
- mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, kExtmarkUndo);
+ mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo);
} else {
- extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, count, 0L,
+ extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L,
kExtmarkUndo);
}
- changed_lines(lnum + 1, 0, lnum + 1, count, true);
+ changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true);
}
/// Deleted "count" lines at line "lnum" in the current buffer.
/// Must be called AFTER the change and after mark_adjust().
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
-void deleted_lines(linenr_T lnum, long count)
+void deleted_lines(linenr_T lnum, linenr_T count)
{
changed_lines(lnum, 0, lnum + count, -count, true);
}
@@ -418,9 +418,9 @@ void deleted_lines_mark(linenr_T lnum, long count)
bool made_empty = (count > 0) && curbuf->b_ml.ml_flags & ML_EMPTY;
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM,
- -count + (made_empty?1:0),
+ -(linenr_T)count + (made_empty?1:0),
kExtmarkUndo);
- changed_lines(lnum, 0, lnum + count, -count, true);
+ changed_lines(lnum, 0, lnum + (linenr_T)count, (linenr_T)(-count), true);
}
/// Marks the area to be redrawn after a change.
@@ -429,7 +429,7 @@ void deleted_lines_mark(linenr_T lnum, long count)
/// @param lnum first line with change
/// @param lnume line below last changed line
/// @param xtra number of extra lines (negative when deleting)
-void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
+void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_T xtra)
{
if (buf->b_mod_set) {
// find the maximum area that must be redisplayed
@@ -474,7 +474,7 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
/// @param do_buf_event some callers like undo/redo call changed_lines() and
/// then increment changedtick *again*. This flag allows these callers to send
/// the nvim_buf_lines_event events after they're done modifying changedtick.
-void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra, bool do_buf_event)
+void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra, bool do_buf_event)
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index e20c0e3f3f..9bc0bef446 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1392,6 +1392,22 @@ long getdigits_long(char_u **pp, bool strict, long def)
return (long)number;
}
+/// Gets a int32_t number from a string.
+///
+/// @see getdigits
+int32_t getdigits_int32(char **pp, bool strict, long def)
+{
+ intmax_t number = getdigits((char_u **)pp, strict, def);
+#if SIZEOF_INTMAX_T > SIZEOF_INT32_T
+ if (strict) {
+ assert(number >= INT32_MIN && number <= INT32_MAX);
+ } else if (!(number >= INT32_MIN && number <= INT32_MAX)) {
+ return (int32_t)def;
+ }
+#endif
+ return (int32_t)number;
+}
+
/// Check that "lbuf" is empty or only contains blanks.
///
/// @param lbuf line buffer to check
diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c
index 30d6ea2505..29dcddfc0d 100644
--- a/src/nvim/debugger.c
+++ b/src/nvim/debugger.c
@@ -506,7 +506,7 @@ static int dbg_parsearg(char_u *arg, garray_T *gap)
if (here) {
bp->dbg_lnum = curwin->w_cursor.lnum;
} else if (gap != &prof_ga && ascii_isdigit(*p)) {
- bp->dbg_lnum = getdigits_long((char_u **)&p, true, 0);
+ bp->dbg_lnum = getdigits_int32(&p, true, 0);
p = skipwhite(p);
} else {
bp->dbg_lnum = 0;
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 1625632842..a622100918 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -248,7 +248,7 @@ void diff_invalidate(buf_T *buf)
/// @param line2
/// @param amount
/// @param amount_after
-void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
+void diff_mark_adjust(linenr_T line1, linenr_T line2, linenr_T amount, linenr_T amount_after)
{
// Handle all tab pages that use the current buffer in a diff.
FOR_ALL_TABS(tp) {
@@ -272,8 +272,8 @@ void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a
/// @param line2
/// @param amount
/// @amount_after
-static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount,
- long amount_after)
+static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2,
+ linenr_T amount, linenr_T amount_after)
{
if (diff_internal()) {
// Will update diffs before redrawing. Set _invalid to update the
@@ -284,8 +284,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
tp->tp_diff_update = true;
}
- long inserted;
- long deleted;
+ linenr_T inserted;
+ linenr_T deleted;
if (line2 == MAXLNUM) {
// mark_adjust(99, MAXLNUM, 9, 0): insert lines
inserted = amount;
@@ -1539,7 +1539,7 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio)
diffout_T *dout = &dio->dio_diff;
char_u linebuf[LBUFLEN]; // only need to hold the diff line
char_u *line;
- long off;
+ linenr_T off;
int i;
int notset = true; // block "*dp" not set yet
diffhunk_T *hunk = NULL; // init to avoid gcc warning
@@ -1662,14 +1662,14 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio)
}
}
dp->df_lnum[idx_new] = hunk->lnum_new;
- dp->df_count[idx_new] = hunk->count_new;
+ dp->df_count[idx_new] = (linenr_T)hunk->count_new;
} else if (notset) {
// new block inside existing one, adjust new block
dp->df_lnum[idx_new] = hunk->lnum_new + off;
- dp->df_count[idx_new] = hunk->count_new - off;
+ dp->df_count[idx_new] = (linenr_T)hunk->count_new - off;
} else {
// second overlap of new block with existing block
- dp->df_count[idx_new] += hunk->count_new - hunk->count_orig
+ dp->df_count[idx_new] += (linenr_T)hunk->count_new - (linenr_T)hunk->count_orig
+ dpl->df_lnum[idx_orig] +
dpl->df_count[idx_orig]
- (dp->df_lnum[idx_orig] +
@@ -1678,7 +1678,7 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio)
// Adjust the size of the block to include all the lines to the
// end of the existing block or the new diff, whatever ends last.
- off = (hunk->lnum_orig + hunk->count_orig)
+ off = (hunk->lnum_orig + (linenr_T)hunk->count_orig)
- (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]);
if (off < 0) {
@@ -1711,9 +1711,9 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio)
dp = diff_alloc_new(curtab, dprev, dp);
dp->df_lnum[idx_orig] = hunk->lnum_orig;
- dp->df_count[idx_orig] = hunk->count_orig;
+ dp->df_count[idx_orig] = (linenr_T)hunk->count_orig;
dp->df_lnum[idx_new] = hunk->lnum_new;
- dp->df_count[idx_new] = hunk->count_new;
+ dp->df_count[idx_new] = (linenr_T)hunk->count_new;
// Set values for other buffers, these must be equal to the
// original buffer, otherwise there would have been a change
@@ -1754,7 +1754,7 @@ static void diff_read(int idx_orig, int idx_new, diffio_T *dio)
/// @param idx_new
static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new)
{
- long off;
+ linenr_T off;
if (dprev == NULL) {
off = 0;
@@ -1896,7 +1896,7 @@ int diff_check(win_T *wp, linenr_T lnum)
maxcount = dp->df_count[i];
}
}
- return (int)(maxcount - dp->df_count[idx]);
+ return maxcount - dp->df_count[idx];
}
/// Compare two entries in diff "dp" and return true if they are equal.
@@ -2097,7 +2097,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin)
towin->w_topfill = fromwin->w_topfill;
} else {
// fromwin has some diff lines
- towin->w_topfill = (int)(dp->df_lnum[fromidx] + max_count - lnum);
+ towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum;
}
}
}
@@ -2670,7 +2670,7 @@ void ex_diffgetput(exarg_T *eap)
// range ends above end of current/from diff block
if (idx_cur == idx_from) {
// :diffput
- i = (int)(dp->df_count[idx_cur] - start_skip - end_skip);
+ i = dp->df_count[idx_cur] - start_skip - end_skip;
if (count > i) {
count = i;
@@ -2745,7 +2745,7 @@ void ex_diffgetput(exarg_T *eap)
// Adjust marks. This will change the following entries!
if (added != 0) {
- mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added,
+ mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, added,
kExtmarkUndo);
if (curwin->w_cursor.lnum >= lnum) {
// Adjust the cursor position if it's in/after the changed
@@ -2757,7 +2757,7 @@ void ex_diffgetput(exarg_T *eap)
}
}
}
- changed_lines(lnum, 0, lnum + count, (long)added, true);
+ changed_lines(lnum, 0, lnum + count, added, true);
if (dfree != NULL) {
// Diff is deleted, update folds in other windows.
@@ -3044,7 +3044,7 @@ static int parse_diff_ed(char_u *line, diffhunk_T *hunk)
// append: {first}a{first}[,{last}]
// delete: {first}[,{last}]d{first}
char_u *p = line;
- long f1 = getdigits(&p, true, 0);
+ linenr_T f1 = getdigits_int32((char **)&p, true, 0);
if (*p == ',') {
p++;
l1 = getdigits(&p, true, 0);
@@ -3074,10 +3074,10 @@ static int parse_diff_ed(char_u *line, diffhunk_T *hunk)
hunk->count_orig = l1 - f1 + 1;
}
if (difftype == 'd') {
- hunk->lnum_new = f2 + 1;
+ hunk->lnum_new = (linenr_T)f2 + 1;
hunk->count_new = 0;
} else {
- hunk->lnum_new = f2;
+ hunk->lnum_new = (linenr_T)f2;
hunk->count_new = l2 - f2 + 1;
}
return OK;
@@ -3125,9 +3125,9 @@ static int parse_diff_unified(char_u *line, diffhunk_T *hunk)
newline = 1;
}
- hunk->lnum_orig = oldline;
+ hunk->lnum_orig = (linenr_T)oldline;
hunk->count_orig = oldcount;
- hunk->lnum_new = newline;
+ hunk->lnum_new = (linenr_T)newline;
hunk->count_new = newcount;
return OK;
@@ -3146,9 +3146,9 @@ static int xdiff_out(long start_a, long count_a, long start_b, long count_b, voi
diffhunk_T *p = xmalloc(sizeof(*p));
ga_grow(&dout->dout_ga, 1);
- p->lnum_orig = start_a + 1;
+ p->lnum_orig = (linenr_T)start_a + 1;
p->count_orig = count_a;
- p->lnum_new = start_b + 1;
+ p->lnum_new = (linenr_T)start_b + 1;
p->count_new = count_b;
((diffhunk_T **)dout->dout_ga.ga_data)[dout->dout_ga.ga_len++] = p;
return 0;
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 41fa34c31e..7bdce3eadd 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -6956,7 +6956,7 @@ int cursor_up(long n, int upd_topline)
lnum = 1;
}
} else {
- lnum -= n;
+ lnum -= (linenr_T)n;
}
curwin->w_cursor.lnum = lnum;
}
@@ -7007,7 +7007,7 @@ int cursor_down(long n, int upd_topline)
lnum = curbuf->b_ml.ml_line_count;
}
} else {
- lnum += n;
+ lnum += (linenr_T)n;
}
curwin->w_cursor.lnum = lnum;
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 7e56f131ba..6fa3f1b427 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -439,7 +439,7 @@ static int sort_compare(const void *s1, const void *s2)
// If two lines have the same value, preserve the original line order.
if (result == 0) {
- return (int)(l1.lnum - l2.lnum);
+ return l1.lnum - l2.lnum;
}
return result;
}
@@ -451,7 +451,7 @@ void ex_sort(exarg_T *eap)
int len;
linenr_T lnum;
long maxlen = 0;
- size_t count = (size_t)(eap->line2 - eap->line1 + 1);
+ size_t count = eap->line2 - eap->line1 + 1;
size_t i;
char *p;
char *s;
@@ -5934,7 +5934,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i
}
}
// Put "|lnum| line" into `str` and append it to the preview buffer.
- snprintf(str, line_size, "|%*ld| %s", col_width - 3,
+ snprintf(str, line_size, "|%*" PRIdLINENR "| %s", col_width - 3,
next_linenr, line);
// Temporarily switch to preview buffer
aucmd_prepbuf(&aco, cmdpreview_buf);
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 0e9c8dcf01..0d69578c26 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1355,13 +1355,13 @@ static void parse_register(exarg_T *eap)
void set_cmd_count(exarg_T *eap, long count, bool validate)
{
if (eap->addr_type != ADDR_LINES) { // e.g. :buffer 2, :sleep 3
- eap->line2 = count;
+ eap->line2 = (linenr_T)count;
if (eap->addr_count == 0) {
eap->addr_count = 1;
}
} else {
eap->line1 = eap->line2;
- eap->line2 += count - 1;
+ eap->line2 += (linenr_T)count - 1;
eap->addr_count++;
// Be vi compatible: no error message for out of range.
if (validate && eap->line2 > curbuf->b_ml.ml_line_count) {
@@ -4243,7 +4243,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
{
int c;
int i;
- long n;
+ linenr_T n;
char *cmd;
pos_T pos;
pos_T *fp;
@@ -4458,7 +4458,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
default:
if (ascii_isdigit(*cmd)) { // absolute line number
- lnum = getdigits_long((char_u **)&cmd, false, 0);
+ lnum = (linenr_T)getdigits((char_u **)&cmd, false, 0);
}
}
@@ -4512,7 +4512,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
if (!ascii_isdigit(*cmd)) { // '+' is '+1', but '+0' is not '+1'
n = 1;
} else {
- n = getdigits((char_u **)&cmd, false, MAXLNUM);
+ n = getdigits_int32(&cmd, false, MAXLNUM);
if (n == MAXLNUM) {
emsg(_(e_line_number_out_of_range));
goto error;
@@ -4535,7 +4535,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
if (i == '-') {
lnum -= n;
} else {
- if (n >= LONG_MAX - lnum) {
+ if (n >= INT32_MAX - lnum) {
emsg(_(e_line_number_out_of_range));
goto error;
}
@@ -8551,11 +8551,11 @@ static void ex_copymove(exarg_T *eap)
}
if (eap->cmdidx == CMD_move) {
- if (do_move(eap->line1, eap->line2, n) == FAIL) {
+ if (do_move(eap->line1, eap->line2, (linenr_T)n) == FAIL) {
return;
}
} else {
- ex_copy(eap->line1, eap->line2, n);
+ ex_copy(eap->line1, eap->line2, (linenr_T)n);
}
u_clearline();
beginline(BL_SOL | BL_FIX);
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c
index 72c7640d3d..b9e0d18f20 100644
--- a/src/nvim/extmark.c
+++ b/src/nvim/extmark.c
@@ -499,8 +499,8 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
}
/// Adjust extmark row for inserted/deleted rows (columns stay fixed).
-void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, long amount, long amount_after,
- ExtmarkOp undo)
+void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount,
+ linenr_T amount_after, ExtmarkOp undo)
{
if (curbuf_splice_pending) {
return;
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
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 432cb25adc..b911eb8b59 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -89,7 +89,7 @@ static int regex_match_line(lua_State *lstate)
}
long bufnr = luaL_checkinteger(lstate, 2);
- long rownr = luaL_checkinteger(lstate, 3);
+ linenr_T rownr = (linenr_T)luaL_checkinteger(lstate, 3);
long start = 0, end = -1;
if (narg >= 4) {
start = luaL_checkinteger(lstate, 4);
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;<