aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2018-04-02 00:41:00 +0300
committerZyX <kp-pav@yandex.ru>2018-04-02 00:41:00 +0300
commit566048240625c5ac9404dfa4c490dbe40105824d (patch)
tree1f88e13be3a3386f4aae9d64a8940ff903748398
parentbf160dd668a47854d011482b17e57f38cf3493dd (diff)
downloadrneovim-566048240625c5ac9404dfa4c490dbe40105824d.tar.gz
rneovim-566048240625c5ac9404dfa4c490dbe40105824d.tar.bz2
rneovim-566048240625c5ac9404dfa4c490dbe40105824d.zip
api/buffer: Fix PVS/V547: use correct border for lnum
Should actually be silencing that for the sake of the case when `long` is actually not 64-bit. But it appears that Vim had already defined maximal line number. And even declared that exact value invalid, so no need in silencing.
-rw-r--r--src/nvim/api/buffer.c8
-rw-r--r--src/nvim/pos.h6
2 files changed, 8 insertions, 6 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index af723639c5..6be981a18e 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -186,12 +186,12 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
for (size_t i = 0; i < rv.size; i++) {
int64_t lnum = start + (int64_t)i;
- if (lnum > LONG_MAX) {
+ if (lnum >= MAXLNUM) {
api_set_error(err, kErrorTypeValidation, "Line index is too high");
goto end;
}
- const char *bufstr = (char *) ml_get_buf(buf, (linenr_T) lnum, false);
+ const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false);
Object str = STRING_OBJ(cstr_to_string(bufstr));
// Vim represents NULs as NLs, but this may confuse clients.
@@ -360,7 +360,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
for (size_t i = 0; i < to_replace; i++) {
int64_t lnum = start + (int64_t)i;
- if (lnum > LONG_MAX) {
+ if (lnum >= MAXLNUM) {
api_set_error(err, kErrorTypeValidation, "Index value is too high");
goto end;
}
@@ -378,7 +378,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
for (size_t i = to_replace; i < new_len; i++) {
int64_t lnum = start + (int64_t)i - 1;
- if (lnum > LONG_MAX) {
+ if (lnum >= MAXLNUM) {
api_set_error(err, kErrorTypeValidation, "Index value is too high");
goto end;
}
diff --git a/src/nvim/pos.h b/src/nvim/pos.h
index 966255e6a4..0a2afd5847 100644
--- a/src/nvim/pos.h
+++ b/src/nvim/pos.h
@@ -10,8 +10,10 @@ typedef int colnr_T;
/// Format used to print values which have colnr_T type
#define PRIdCOLNR "d"
-#define MAXLNUM 0x7fffffff // maximum (invalid) line number
-#define MAXCOL 0x7fffffff // maximum column number, 31 bits
+/// Maximal (invalid) line number
+enum { MAXLNUM = 0x7fffffff };
+/// Maximal column number, 31 bits
+enum { MAXCOL = 0x7fffffff };
/*
* position in file or buffer