aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-12-10 13:38:35 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-12-10 14:29:24 +0800
commitac230370f3de2925b3ca9443e8d52d7fc4311aba (patch)
tree89227b85319424c955be8fa9f2b3466eee46e8db
parent2336389d236f3d80575a5139e92c551c005b0eff (diff)
downloadrneovim-ac230370f3de2925b3ca9443e8d52d7fc4311aba.tar.gz
rneovim-ac230370f3de2925b3ca9443e8d52d7fc4311aba.tar.bz2
rneovim-ac230370f3de2925b3ca9443e8d52d7fc4311aba.zip
vim-patch:9.0.2113: Coverity warns for another overflow in shift_line()
Problem: Coverity warns for another overflow in shift_line() Solution: Test for INT_MAX after the if condition, cast integer values to (long long) before multiplying. https://github.com/vim/vim/commit/22a97fc241361aa91bda84e5344d5b7c0cda3e81 Co-authored-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--src/nvim/ops.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 1bba1154f2..5325beb654 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -296,19 +296,19 @@ void shift_line(bool left, bool round, int amount, int call_changed_bytes)
} else {
i += amount;
}
- count = i * sw_val;
+ count = (int64_t)i * (int64_t)sw_val;
} else { // original vi indent
if (left) {
- count = MAX(count - sw_val * amount, 0);
+ count = MAX(count - (int64_t)sw_val * (int64_t)amount, 0);
} else {
- if ((int64_t)sw_val * (int64_t)amount > INT_MAX - count) {
- count = INT_MAX;
- } else {
- count += (int64_t)sw_val * (int64_t)amount;
- }
+ count += (int64_t)sw_val * (int64_t)amount;
}
}
+ if (count > INT_MAX) {
+ count = INT_MAX;
+ }
+
// Set new indent
if (State & VREPLACE_FLAG) {
change_indent(INDENT_SET, (int)count, false, call_changed_bytes);