aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-12-10 13:48:59 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-12-10 14:29:24 +0800
commit6c81c16e1b8dd1650960bf1cea57ce05b26f7822 (patch)
tree54d65f418299efb5382065fdf55cd78275df2e50 /src/nvim/ops.c
parent7a7ed0c8ac2d66d695da5bd3f90536e8c5c11ccc (diff)
downloadrneovim-6c81c16e1b8dd1650960bf1cea57ce05b26f7822.tar.gz
rneovim-6c81c16e1b8dd1650960bf1cea57ce05b26f7822.tar.bz2
rneovim-6c81c16e1b8dd1650960bf1cea57ce05b26f7822.zip
vim-patch:9.0.2124: INT overflow detection logic can be simplified
Problem: INT overflow logic can be simplified Solution: introduce trim_to_int() function closes: vim/vim#13556 https://github.com/vim/vim/commit/2b0882fa6555b4d0197afbdfc32a4533cf6aacf4 vim-patch:9.0.2138: Overflow logic requires long long Problem: Overflow logic requires long long Solution: Define vimlong_T data type to make life easier for porters closes: vim/vim#13598 https://github.com/vim/vim/commit/fda700cb04612fe2f9301a9ba820309175decabf Cherry-pick ops.c change from patch 9.1.0608. Co-authored-by: Ernie Rael <errael@raelity.com>
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 5325beb654..9524c67301 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -48,6 +48,7 @@
#include "nvim/macros_defs.h"
#include "nvim/mark.h"
#include "nvim/mark_defs.h"
+#include "nvim/math.h"
#include "nvim/mbyte.h"
#include "nvim/mbyte_defs.h"
#include "nvim/memline.h"
@@ -286,8 +287,8 @@ void shift_line(bool left, bool round, int amount, int call_changed_bytes)
int64_t count = get_indent(); // get current indent
if (round) { // round off indent
- int i = (int)(count / sw_val); // number of 'shiftwidth' rounded down
- int j = (int)(count % sw_val); // extra spaces
+ int i = trim_to_int(count / sw_val); // number of 'shiftwidth' rounded down
+ int j = trim_to_int(count % sw_val); // extra spaces
if (j && left) { // first remove extra spaces
amount--;
}
@@ -305,15 +306,11 @@ void shift_line(bool left, bool round, int amount, int call_changed_bytes)
}
}
- if (count > INT_MAX) {
- count = INT_MAX;
- }
-
// Set new indent
if (State & VREPLACE_FLAG) {
- change_indent(INDENT_SET, (int)count, false, call_changed_bytes);
+ change_indent(INDENT_SET, trim_to_int(count), false, call_changed_bytes);
} else {
- set_indent((int)count, call_changed_bytes ? SIN_CHANGED : 0);
+ set_indent(trim_to_int(count), call_changed_bytes ? SIN_CHANGED : 0);
}
}