From ac230370f3de2925b3ca9443e8d52d7fc4311aba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 Dec 2024 13:38:35 +0800 Subject: [PATCH] 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 --- src/nvim/ops.c | 14 +++++++------- 1 file 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);