aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2015-02-20 18:50:06 +0100
committerEliseo Martínez <eliseomarmol@gmail.com>2015-02-20 18:50:06 +0100
commitd35820379f57c73e594a0c29713d64ef9e6ada22 (patch)
tree5980e19bc52ecfacbed7000a3421140c0541f903 /src
parent03dd2114a78f513c362ccc5ec4de700f11a2db0e (diff)
parenta4bed17d0d33904eb9cced9a6d3f99388648b408 (diff)
downloadrneovim-d35820379f57c73e594a0c29713d64ef9e6ada22.tar.gz
rneovim-d35820379f57c73e594a0c29713d64ef9e6ada22.tar.bz2
rneovim-d35820379f57c73e594a0c29713d64ef9e6ada22.zip
Merge #1983: Fix coverity issues. (5)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_eval.c3
-rw-r--r--src/nvim/message.c103
-rw-r--r--src/nvim/screen.c4
3 files changed, 51 insertions, 59 deletions
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index b0c4e14f46..cc474d22ff 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -1028,7 +1028,8 @@ void ex_continue(exarg_T *eap)
* next). Therefor, inactivate all conditionals except the ":while"
* itself (if reached). */
idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
- if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) {
+ assert(idx >= 0);
+ if (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR)) {
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
/*
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 825b8b2550..5179921d76 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -3101,6 +3101,7 @@ int vim_snprintf(char *str, size_t str_m, char *fmt, ...)
int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
{
size_t str_l = 0;
+ bool str_avail = str_l < str_m;
char *p = fmt;
int arg_idx = 1;
@@ -3108,15 +3109,15 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
p = "";
while (*p != NUL) {
if (*p != '%') {
- size_t n = xstrchrnul(p + 1, '%') - p;
-
/* Copy up to the next '%' or NUL without any changes. */
- if (str_l < str_m) {
+ size_t n = (size_t)(xstrchrnul(p + 1, '%') - p);
+ if (str_avail) {
size_t avail = str_m - str_l;
-
- memmove(str + str_l, p, n > avail ? avail : n);
+ memmove(str + str_l, p, MIN(n, avail));
+ str_avail = n < avail;
}
p += n;
+ assert(n <= SIZE_MAX - str_l);
str_l += n;
} else {
size_t min_field_width = 0, precision = 0;
@@ -3666,17 +3667,16 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
* this does not include the zero padding in case of numerical
* conversions*/
if (!justify_left) {
- /* left padding with blank or zero */
- int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad));
-
- if (pn > 0) {
- if (str_l < str_m) {
+ assert(str_arg_l <= SIZE_MAX - number_of_zeros_to_pad);
+ if (min_field_width > str_arg_l + number_of_zeros_to_pad) {
+ /* left padding with blank or zero */
+ size_t pn = min_field_width - (str_arg_l + number_of_zeros_to_pad);
+ if (str_avail) {
size_t avail = str_m - str_l;
-
- memset(str + str_l, zero_padding ? '0' : ' ',
- (size_t)pn > avail ? avail
- : (size_t)pn);
+ memset(str + str_l, zero_padding ? '0' : ' ', MIN(pn, avail));
+ str_avail = pn < avail;
}
+ assert(pn <= SIZE_MAX - str_l);
str_l += pn;
}
}
@@ -3688,67 +3688,58 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
* force it to be copied later in its entirety */
zero_padding_insertion_ind = 0;
} else {
- /* insert first part of numerics (sign or '0x') before zero
- * padding */
- int zn = (int)zero_padding_insertion_ind;
-
- if (zn > 0) {
- if (str_l < str_m) {
+ /* insert first part of numerics (sign or '0x') before zero padding */
+ if (zero_padding_insertion_ind > 0) {
+ size_t zn = zero_padding_insertion_ind;
+ if (str_avail) {
size_t avail = str_m - str_l;
-
- memmove(str + str_l, str_arg,
- (size_t)zn > avail ? avail
- : (size_t)zn);
+ memmove(str + str_l, str_arg, MIN(zn, avail));
+ str_avail = zn < avail;
}
+ assert(zn <= SIZE_MAX - str_l);
str_l += zn;
}
- /* insert zero padding as requested by the precision or min
- * field width */
- zn = (int)number_of_zeros_to_pad;
- if (zn > 0) {
- if (str_l < str_m) {
- size_t avail = str_m-str_l;
-
- memset(str + str_l, '0',
- (size_t)zn > avail ? avail
- : (size_t)zn);
+ /* insert zero padding as requested by precision or min field width */
+ if (number_of_zeros_to_pad > 0) {
+ size_t zn = number_of_zeros_to_pad;
+ if (str_avail) {
+ size_t avail = str_m - str_l;
+ memset(str + str_l, '0', MIN(zn, avail));
+ str_avail = zn < avail;
}
+ assert(zn <= SIZE_MAX - str_l);
str_l += zn;
}
}
/* insert formatted string
* (or as-is conversion specifier for unknown conversions) */
- {
- int sn = (int)(str_arg_l - zero_padding_insertion_ind);
-
- if (sn > 0) {
- if (str_l < str_m) {
- size_t avail = str_m - str_l;
-
- memmove(str + str_l,
- str_arg + zero_padding_insertion_ind,
- (size_t)sn > avail ? avail : (size_t)sn);
- }
- str_l += sn;
+ if (str_arg_l > zero_padding_insertion_ind) {
+ size_t sn = str_arg_l - zero_padding_insertion_ind;
+ if (str_avail) {
+ size_t avail = str_m - str_l;
+ memmove(str + str_l,
+ str_arg + zero_padding_insertion_ind,
+ MIN(sn, avail));
+ str_avail = sn < avail;
}
+ assert(sn <= SIZE_MAX - str_l);
+ str_l += sn;
}
/* insert right padding */
if (justify_left) {
- /* right blank padding to the field width */
- int pn = (int)(min_field_width
- - (str_arg_l + number_of_zeros_to_pad));
-
- if (pn > 0) {
- if (str_l < str_m) {
+ assert(str_arg_l <= SIZE_MAX - number_of_zeros_to_pad);
+ if (min_field_width > str_arg_l + number_of_zeros_to_pad) {
+ /* right blank padding to the field width */
+ size_t pn = min_field_width - (str_arg_l + number_of_zeros_to_pad);
+ if (str_avail) {
size_t avail = str_m - str_l;
-
- memset(str + str_l, ' ',
- (size_t)pn > avail ? avail
- : (size_t)pn);
+ memset(str + str_l, ' ', MIN(pn, avail));
+ str_avail = pn < avail;
}
+ assert(pn <= SIZE_MAX - str_l);
str_l += pn;
}
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 80a87e9f7b..cec5753879 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -5654,7 +5654,7 @@ next_search_hl_pos(
continue;
}
if (posmatch->pos[i].lnum == lnum) {
- if (shl->lnum == lnum) {
+ if (bot != -1) {
// partially sort positions by column numbers
// on the same line
if (posmatch->pos[i].col < posmatch->pos[bot].col) {
@@ -5670,7 +5670,7 @@ next_search_hl_pos(
}
}
posmatch->cur = 0;
- if (shl->lnum == lnum) {
+ if (bot != -1) {
colnr_T start = posmatch->pos[bot].col == 0
? 0: posmatch->pos[bot].col - 1;
colnr_T end = posmatch->pos[bot].col == 0