refactor: fix clang and PVS warnings (#19532)

This commit is contained in:
zeertzjq
2022-07-28 06:05:33 +08:00
committed by GitHub
parent 7d9e68669c
commit e0c433833f
9 changed files with 12 additions and 9 deletions

View File

@@ -514,6 +514,7 @@ static const char *list_arg_vars(exarg_T *eap, const char *arg, int *first)
const char *const used_name = (arg == arg_subsc const char *const used_name = (arg == arg_subsc
? name ? name
: name_start); : name_start);
assert(used_name != NULL);
const ptrdiff_t name_size = (used_name == tofree const ptrdiff_t name_size = (used_name == tofree
? (ptrdiff_t)strlen(used_name) ? (ptrdiff_t)strlen(used_name)
: (arg - used_name)); : (arg - used_name));

View File

@@ -3052,6 +3052,7 @@ char *find_ex_command(exarg_T *eap, int *full)
} else { } else {
eap->cmdidx = CMD_bang; eap->cmdidx = CMD_bang;
} }
assert(eap->cmdidx >= 0);
for (; (int)eap->cmdidx < CMD_SIZE; for (; (int)eap->cmdidx < CMD_SIZE;
eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) { eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) {

View File

@@ -3336,7 +3336,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line)
{ {
Arena arena = ARENA_EMPTY; Arena arena = ARENA_EMPTY;
arena_start(&arena, &ui_ext_fixblk); arena_start(&arena, &ui_ext_fixblk);
Array content = ARRAY_DICT_INIT; Array content;
if (cmdline_star) { if (cmdline_star) {
content = arena_array(&arena, 1); content = arena_array(&arena, 1);
size_t len = 0; size_t len = 0;

View File

@@ -956,8 +956,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
linep++; linep++;
} }
size_t key_len = (size_t)(linep - key_start); size_t key_len = (size_t)(linep - key_start);
if (key_len > sizeof key - 1) { if (key_len > sizeof(key) - 1) {
semsg(_("E423: Illegal argument")); emsg(_("E423: Illegal argument"));
error = true; error = true;
break; break;
} }
@@ -1004,8 +1004,8 @@ void do_highlight(const char *line, const bool forceit, const bool init)
break; break;
} }
size_t arg_len = (size_t)(linep - arg_start); size_t arg_len = (size_t)(linep - arg_start);
if (arg_len > sizeof arg - 1) { if (arg_len > sizeof(arg) - 1) {
semsg(_("E423: Illegal argument")); emsg(_("E423: Illegal argument"));
error = true; error = true;
break; break;
} }

View File

@@ -310,7 +310,7 @@ static bool v_do_log_to_file(FILE *log_file, int log_level, const char *context,
const char *parent = path_tail(os_getenv(ENV_NVIM)); const char *parent = path_tail(os_getenv(ENV_NVIM));
// Servername. Empty until starting=false. // Servername. Empty until starting=false.
const char *serv = path_tail(get_vim_var_str(VV_SEND_SERVER)); const char *serv = path_tail(get_vim_var_str(VV_SEND_SERVER));
if (parent && parent[0] != NUL) { if (parent[0] != NUL) {
snprintf(name, sizeof(name), "%s/c", parent); // "/c" indicates child. snprintf(name, sizeof(name), "%s/c", parent); // "/c" indicates child.
} else if (serv[0] != NUL) { } else if (serv[0] != NUL) {
snprintf(name, sizeof(name), "%s", serv); snprintf(name, sizeof(name), "%s", serv);

View File

@@ -491,7 +491,7 @@ fmark_T *mark_get_visual(buf_T *buf, int name)
mark = pos_to_mark(buf, NULL, endp); mark = pos_to_mark(buf, NULL, endp);
} }
if (mark != NULL && buf->b_visual.vi_mode == 'V') { if (buf->b_visual.vi_mode == 'V') {
if (name == '<') { if (name == '<') {
mark->mark.col = 0; mark->mark.col = 0;
} else { } else {

View File

@@ -425,8 +425,8 @@ redo:
arena_start(&p->arena, &p->reuse_blk); arena_start(&p->arena, &p->reuse_blk);
p->grid_line_event = arena_alloc(&p->arena, sizeof *p->grid_line_event, true); p->grid_line_event = arena_alloc(&p->arena, sizeof *p->grid_line_event, true);
g = p->grid_line_event; g = p->grid_line_event;
FALLTHROUGH;
} }
FALLTHROUGH;
case 13: case 13:
NEXT_TYPE(tok, MPACK_TOKEN_ARRAY); NEXT_TYPE(tok, MPACK_TOKEN_ARRAY);

View File

@@ -5102,6 +5102,7 @@ static void nv_brackets(cmdarg_T *cap)
} else if (cap->nchar == '\'' || cap->nchar == '`') { } else if (cap->nchar == '\'' || cap->nchar == '`') {
// "['", "[`", "]'" and "]`": jump to next mark // "['", "[`", "]'" and "]`": jump to next mark
fmark_T *fm = pos_to_mark(curbuf, NULL, curwin->w_cursor); fmark_T *fm = pos_to_mark(curbuf, NULL, curwin->w_cursor);
assert(fm != NULL);
fmark_T *prev_fm; fmark_T *prev_fm;
for (n = cap->count1; n > 0; n--) { for (n = cap->count1; n > 0; n--) {
prev_fm = fm; prev_fm = fm;

View File

@@ -2119,7 +2119,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
bool has_decor = false; // this buffer has decoration bool has_decor = false; // this buffer has decoration
int win_col_offset = 0; // offset for window columns int win_col_offset = 0; // offset for window columns
char_u buf_fold[FOLD_TEXT_LEN + 1]; // Hold value returned by get_foldtext char_u buf_fold[FOLD_TEXT_LEN]; // Hold value returned by get_foldtext
bool area_active = false; bool area_active = false;