aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-09 11:36:11 +0800
committerGitHub <noreply@github.com>2023-12-09 11:36:11 +0800
commit2ebd328a798778825be61015acd975d8a929dfec (patch)
tree9f27693d0cc5c92cc9ad0b0f907800fea4723eb1
parentc651fb30427a3c645b4b1bd8a9b7e767af51e014 (diff)
downloadrneovim-2ebd328a798778825be61015acd975d8a929dfec.tar.gz
rneovim-2ebd328a798778825be61015acd975d8a929dfec.tar.bz2
rneovim-2ebd328a798778825be61015acd975d8a929dfec.zip
refactor: format casting of negative number better (#26482)
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/eval/funcs.c2
-rw-r--r--src/nvim/lua/converter.c2
-rw-r--r--src/nvim/mark.c6
-rw-r--r--src/nvim/ops.c4
-rw-r--r--src/nvim/textformat.c2
6 files changed, 9 insertions, 9 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 16c1231682..2bbc8b58e7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5029,7 +5029,7 @@ size_t string2float(const char *const text, float_T *const ret_value)
return 3;
}
if (STRNICMP(text, "-inf", 3) == 0) {
- *ret_value = (float_T) - INFINITY;
+ *ret_value = (float_T)(-INFINITY);
return 4;
}
if (STRNICMP(text, "nan", 3) == 0) {
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 15b81f2f56..b4f0be85e5 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2171,7 +2171,7 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
- if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
+ if (f <= (float_T)(-VARNUMBER_MAX) + DBL_EPSILON) {
rettv->vval.v_number = -VARNUMBER_MAX;
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
rettv->vval.v_number = VARNUMBER_MAX;
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index ca0be28fac..e26e38f577 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -1254,7 +1254,7 @@ handle_T nlua_pop_handle(lua_State *lstate, Error *err)
handle_T ret;
if (lua_type(lstate, -1) != LUA_TNUMBER) {
api_set_error(err, kErrorTypeValidation, "Expected Lua number");
- ret = (handle_T) - 1;
+ ret = (handle_T)(-1);
} else {
ret = (handle_T)lua_tonumber(lstate, -1);
}
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 5839cf7a2e..1e2462970f 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -1288,12 +1288,12 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount
if (posp->lnum == lnum && posp->col >= mincol) { \
posp->lnum += lnum_amount; \
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
- if (col_amount < 0 && posp->col <= (colnr_T) - col_amount) { \
+ if (col_amount < 0 && posp->col <= -col_amount) { \
posp->col = 0; \
} else if (posp->col < spaces_removed) { \
- posp->col = (int)col_amount + spaces_removed; \
+ posp->col = col_amount + spaces_removed; \
} else { \
- posp->col += (colnr_T)col_amount; \
+ posp->col += col_amount; \
} \
} \
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 3a4e87edf7..16aa46e97d 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4630,13 +4630,13 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if (!pre) {
if (subtract) {
if (n > oldn) {
- n = 1 + (n ^ (uvarnumber_T) - 1);
+ n = 1 + (n ^ (uvarnumber_T)(-1));
negative ^= true;
}
} else {
// add
if (n < oldn) {
- n = (n ^ (uvarnumber_T) - 1);
+ n = (n ^ (uvarnumber_T)(-1));
negative ^= true;
}
}
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 5d7f5b747b..8e52ad660b 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -678,7 +678,7 @@ void auto_format(bool trailblank, bool prev_line)
// Do the formatting and restore the cursor position. "saved_cursor" will
// be adjusted for the text formatting.
saved_cursor = pos;
- format_lines((linenr_T) - 1, false);
+ format_lines(-1, false);
curwin->w_cursor = saved_cursor;
saved_cursor.lnum = 0;