aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/indent_c.c9
-rw-r--r--src/nvim/math.c6
-rw-r--r--src/nvim/ops.c13
3 files changed, 14 insertions, 14 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 9b5c80dd09..c9b7a1ba3f 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -14,6 +14,7 @@
#include "nvim/indent_c.h"
#include "nvim/macros_defs.h"
#include "nvim/mark_defs.h"
+#include "nvim/math.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/option.h"
@@ -1708,7 +1709,7 @@ void parse_cino(buf_T *buf)
} else {
n *= sw;
if (divider) {
- n += (sw * fraction + divider / 2) / divider;
+ n += ((int64_t)sw * fraction + divider / 2) / divider;
}
}
p++;
@@ -1717,11 +1718,7 @@ void parse_cino(buf_T *buf)
n = -n;
}
- if (n > INT_MAX) {
- n = INT_MAX;
- } else if (n < INT_MIN) {
- n = INT_MIN;
- }
+ n = trim_to_int(n);
// When adding an entry here, also update the default 'cinoptions' in
// doc/indent.txt, and add explanation for it!
diff --git a/src/nvim/math.c b/src/nvim/math.c
index 4ca212413b..0b5886d36c 100644
--- a/src/nvim/math.c
+++ b/src/nvim/math.c
@@ -106,3 +106,9 @@ int vim_append_digit_int(int *value, int digit)
*value = x * 10 + digit;
return OK;
}
+
+/// Return something that fits into an int.
+int trim_to_int(int64_t x)
+{
+ return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : (int)x;
+}
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);
}
}