mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 03:16: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:
@@ -1146,8 +1146,8 @@ bool scrollup(long line_count, int byfold)
|
||||
curwin->w_botline += lnum - curwin->w_topline;
|
||||
curwin->w_topline = lnum;
|
||||
} else {
|
||||
curwin->w_topline += line_count;
|
||||
curwin->w_botline += line_count; // approximate w_botline
|
||||
curwin->w_topline += (linenr_T)line_count;
|
||||
curwin->w_botline += (linenr_T)line_count; // approximate w_botline
|
||||
}
|
||||
|
||||
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
|
||||
@@ -1903,7 +1903,7 @@ int onepage(Direction dir, long count)
|
||||
if (p_window <= 2) {
|
||||
++curwin->w_topline;
|
||||
} else {
|
||||
curwin->w_topline += p_window - 2;
|
||||
curwin->w_topline += (linenr_T)p_window - 2;
|
||||
}
|
||||
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_topline = curbuf->b_ml.ml_line_count;
|
||||
@@ -1939,12 +1939,12 @@ int onepage(Direction dir, long count)
|
||||
if (p_window <= 2) {
|
||||
--curwin->w_topline;
|
||||
} else {
|
||||
curwin->w_topline -= p_window - 2;
|
||||
curwin->w_topline -= (linenr_T)p_window - 2;
|
||||
}
|
||||
if (curwin->w_topline < 1) {
|
||||
curwin->w_topline = 1;
|
||||
}
|
||||
curwin->w_cursor.lnum = curwin->w_topline + p_window - 1;
|
||||
curwin->w_cursor.lnum = curwin->w_topline + (linenr_T)p_window - 1;
|
||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||
}
|
||||
|
Reference in New Issue
Block a user