mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +00:00
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:
@@ -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) {
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user