mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 11:25:33 +00:00
Merge #1983: Fix coverity issues. (5)
This commit is contained in:
@@ -1028,7 +1028,8 @@ void ex_continue(exarg_T *eap)
|
|||||||
* next). Therefor, inactivate all conditionals except the ":while"
|
* next). Therefor, inactivate all conditionals except the ":while"
|
||||||
* itself (if reached). */
|
* itself (if reached). */
|
||||||
idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
|
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);
|
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -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)
|
int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs)
|
||||||
{
|
{
|
||||||
size_t str_l = 0;
|
size_t str_l = 0;
|
||||||
|
bool str_avail = str_l < str_m;
|
||||||
char *p = fmt;
|
char *p = fmt;
|
||||||
int arg_idx = 1;
|
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 = "";
|
p = "";
|
||||||
while (*p != NUL) {
|
while (*p != NUL) {
|
||||||
if (*p != '%') {
|
if (*p != '%') {
|
||||||
size_t n = xstrchrnul(p + 1, '%') - p;
|
|
||||||
|
|
||||||
/* Copy up to the next '%' or NUL without any changes. */
|
/* 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;
|
size_t avail = str_m - str_l;
|
||||||
|
memmove(str + str_l, p, MIN(n, avail));
|
||||||
memmove(str + str_l, p, n > avail ? avail : n);
|
str_avail = n < avail;
|
||||||
}
|
}
|
||||||
p += n;
|
p += n;
|
||||||
|
assert(n <= SIZE_MAX - str_l);
|
||||||
str_l += n;
|
str_l += n;
|
||||||
} else {
|
} else {
|
||||||
size_t min_field_width = 0, precision = 0;
|
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
|
* this does not include the zero padding in case of numerical
|
||||||
* conversions*/
|
* conversions*/
|
||||||
if (!justify_left) {
|
if (!justify_left) {
|
||||||
|
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 */
|
/* left padding with blank or zero */
|
||||||
int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad));
|
size_t pn = min_field_width - (str_arg_l + number_of_zeros_to_pad);
|
||||||
|
if (str_avail) {
|
||||||
if (pn > 0) {
|
|
||||||
if (str_l < str_m) {
|
|
||||||
size_t avail = str_m - str_l;
|
size_t avail = str_m - str_l;
|
||||||
|
memset(str + str_l, zero_padding ? '0' : ' ', MIN(pn, avail));
|
||||||
memset(str + str_l, zero_padding ? '0' : ' ',
|
str_avail = pn < avail;
|
||||||
(size_t)pn > avail ? avail
|
|
||||||
: (size_t)pn);
|
|
||||||
}
|
}
|
||||||
|
assert(pn <= SIZE_MAX - str_l);
|
||||||
str_l += pn;
|
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 */
|
* force it to be copied later in its entirety */
|
||||||
zero_padding_insertion_ind = 0;
|
zero_padding_insertion_ind = 0;
|
||||||
} else {
|
} else {
|
||||||
/* insert first part of numerics (sign or '0x') before zero
|
/* insert first part of numerics (sign or '0x') before zero padding */
|
||||||
* padding */
|
if (zero_padding_insertion_ind > 0) {
|
||||||
int zn = (int)zero_padding_insertion_ind;
|
size_t zn = zero_padding_insertion_ind;
|
||||||
|
if (str_avail) {
|
||||||
if (zn > 0) {
|
|
||||||
if (str_l < str_m) {
|
|
||||||
size_t avail = str_m - str_l;
|
size_t avail = str_m - str_l;
|
||||||
|
memmove(str + str_l, str_arg, MIN(zn, avail));
|
||||||
memmove(str + str_l, str_arg,
|
str_avail = zn < avail;
|
||||||
(size_t)zn > avail ? avail
|
|
||||||
: (size_t)zn);
|
|
||||||
}
|
}
|
||||||
|
assert(zn <= SIZE_MAX - str_l);
|
||||||
str_l += zn;
|
str_l += zn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* insert zero padding as requested by the precision or min
|
/* insert zero padding as requested by precision or min field width */
|
||||||
* field width */
|
if (number_of_zeros_to_pad > 0) {
|
||||||
zn = (int)number_of_zeros_to_pad;
|
size_t zn = number_of_zeros_to_pad;
|
||||||
if (zn > 0) {
|
if (str_avail) {
|
||||||
if (str_l < str_m) {
|
|
||||||
size_t avail = str_m - str_l;
|
size_t avail = str_m - str_l;
|
||||||
|
memset(str + str_l, '0', MIN(zn, avail));
|
||||||
memset(str + str_l, '0',
|
str_avail = zn < avail;
|
||||||
(size_t)zn > avail ? avail
|
|
||||||
: (size_t)zn);
|
|
||||||
}
|
}
|
||||||
|
assert(zn <= SIZE_MAX - str_l);
|
||||||
str_l += zn;
|
str_l += zn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* insert formatted string
|
/* insert formatted string
|
||||||
* (or as-is conversion specifier for unknown conversions) */
|
* (or as-is conversion specifier for unknown conversions) */
|
||||||
{
|
if (str_arg_l > zero_padding_insertion_ind) {
|
||||||
int sn = (int)(str_arg_l - zero_padding_insertion_ind);
|
size_t sn = str_arg_l - zero_padding_insertion_ind;
|
||||||
|
if (str_avail) {
|
||||||
if (sn > 0) {
|
|
||||||
if (str_l < str_m) {
|
|
||||||
size_t avail = str_m - str_l;
|
size_t avail = str_m - str_l;
|
||||||
|
|
||||||
memmove(str + str_l,
|
memmove(str + str_l,
|
||||||
str_arg + zero_padding_insertion_ind,
|
str_arg + zero_padding_insertion_ind,
|
||||||
(size_t)sn > avail ? avail : (size_t)sn);
|
MIN(sn, avail));
|
||||||
|
str_avail = sn < avail;
|
||||||
}
|
}
|
||||||
|
assert(sn <= SIZE_MAX - str_l);
|
||||||
str_l += sn;
|
str_l += sn;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* insert right padding */
|
/* insert right padding */
|
||||||
if (justify_left) {
|
if (justify_left) {
|
||||||
|
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 */
|
/* right blank padding to the field width */
|
||||||
int pn = (int)(min_field_width
|
size_t pn = min_field_width - (str_arg_l + number_of_zeros_to_pad);
|
||||||
- (str_arg_l + number_of_zeros_to_pad));
|
if (str_avail) {
|
||||||
|
|
||||||
if (pn > 0) {
|
|
||||||
if (str_l < str_m) {
|
|
||||||
size_t avail = str_m - str_l;
|
size_t avail = str_m - str_l;
|
||||||
|
memset(str + str_l, ' ', MIN(pn, avail));
|
||||||
memset(str + str_l, ' ',
|
str_avail = pn < avail;
|
||||||
(size_t)pn > avail ? avail
|
|
||||||
: (size_t)pn);
|
|
||||||
}
|
}
|
||||||
|
assert(pn <= SIZE_MAX - str_l);
|
||||||
str_l += pn;
|
str_l += pn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5654,7 +5654,7 @@ next_search_hl_pos(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (posmatch->pos[i].lnum == lnum) {
|
if (posmatch->pos[i].lnum == lnum) {
|
||||||
if (shl->lnum == lnum) {
|
if (bot != -1) {
|
||||||
// partially sort positions by column numbers
|
// partially sort positions by column numbers
|
||||||
// on the same line
|
// on the same line
|
||||||
if (posmatch->pos[i].col < posmatch->pos[bot].col) {
|
if (posmatch->pos[i].col < posmatch->pos[bot].col) {
|
||||||
@@ -5670,7 +5670,7 @@ next_search_hl_pos(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
posmatch->cur = 0;
|
posmatch->cur = 0;
|
||||||
if (shl->lnum == lnum) {
|
if (bot != -1) {
|
||||||
colnr_T start = posmatch->pos[bot].col == 0
|
colnr_T start = posmatch->pos[bot].col == 0
|
||||||
? 0: posmatch->pos[bot].col - 1;
|
? 0: posmatch->pos[bot].col - 1;
|
||||||
colnr_T end = posmatch->pos[bot].col == 0
|
colnr_T end = posmatch->pos[bot].col == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user