refactor: clint (#20600)

This commit is contained in:
Lewis Russell
2022-10-12 14:53:40 +01:00
committed by GitHub
parent 024f6880b5
commit 0ef6aaa3a7
14 changed files with 59 additions and 77 deletions

View File

@@ -271,11 +271,9 @@ typval_T decode_string(const char *const s, const size_t len, const TriState has
list_T *const list = tv_list_alloc(kListLenMayKnow); list_T *const list = tv_list_alloc(kListLenMayKnow);
tv_list_ref(list); tv_list_ref(list);
create_special_dict(&tv, kMPString, create_special_dict(&tv, kMPString,
((typval_T){ (typval_T){ .v_type = VAR_LIST,
.v_type = VAR_LIST,
.v_lock = VAR_UNLOCKED, .v_lock = VAR_UNLOCKED,
.vval = { .v_list = list }, .vval = { .v_list = list } });
}));
const int elw_ret = encode_list_write((void *)list, s, len); const int elw_ret = encode_list_write((void *)list, s, len);
if (s_allocated) { if (s_allocated) {
xfree((void *)s); xfree((void *)s);
@@ -368,7 +366,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
goto parse_json_string_fail; goto parse_json_string_fail;
} }
} else { } else {
uint8_t p_byte = (uint8_t)*p; uint8_t p_byte = (uint8_t)(*p);
// unescaped = %x20-21 / %x23-5B / %x5D-10FFFF // unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
if (p_byte < 0x20) { if (p_byte < 0x20) {
semsg(_("E474: ASCII control characters cannot be present " semsg(_("E474: ASCII control characters cannot be present "
@@ -469,7 +467,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
['r'] = CAR, ['r'] = CAR,
['f'] = FF, ['f'] = FF,
}; };
*str_end++ = escapes[(int)*t]; *str_end++ = escapes[(int)(*t)];
break; break;
} }
default: default:
@@ -838,12 +836,10 @@ json_decode_string_cycle_start:
.v_lock = VAR_UNLOCKED, .v_lock = VAR_UNLOCKED,
.vval = { .v_list = list }, .vval = { .v_list = list },
}; };
kv_push(container_stack, ((ContainerStackItem) { kv_push(container_stack, ((ContainerStackItem) { .stack_index = kv_size(stack),
.stack_index = kv_size(stack),
.s = p, .s = p,
.container = tv, .container = tv,
.special_val = NULL, .special_val = NULL }));
}));
kv_push(stack, OBJ(tv, false, didcomma, didcolon)); kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break; break;
} }
@@ -862,12 +858,10 @@ json_decode_string_cycle_start:
.vval = { .v_dict = dict }, .vval = { .v_dict = dict },
}; };
} }
kv_push(container_stack, ((ContainerStackItem) { kv_push(container_stack, ((ContainerStackItem) { .stack_index = kv_size(stack),
.stack_index = kv_size(stack),
.s = p, .s = p,
.container = tv, .container = tv,
.special_val = val_list, .special_val = val_list }));
}));
kv_push(stack, OBJ(tv, false, didcomma, didcolon)); kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break; break;
} }
@@ -1089,11 +1083,9 @@ msgpack_to_vim_generic_map: {}
tv_list_append_number(list, mobj.via.ext.type); tv_list_append_number(list, mobj.via.ext.type);
list_T *const ext_val_list = tv_list_alloc(kListLenMayKnow); list_T *const ext_val_list = tv_list_alloc(kListLenMayKnow);
tv_list_append_list(list, ext_val_list); tv_list_append_list(list, ext_val_list);
create_special_dict(rettv, kMPExt, ((typval_T) { create_special_dict(rettv, kMPExt, ((typval_T) { .v_type = VAR_LIST,
.v_type = VAR_LIST,
.v_lock = VAR_UNLOCKED, .v_lock = VAR_UNLOCKED,
.vval = { .v_list = list }, .vval = { .v_list = list } }));
}));
if (encode_list_write((void *)ext_val_list, mobj.via.ext.ptr, if (encode_list_write((void *)ext_val_list, mobj.via.ext.ptr,
mobj.via.ext.size) == -1) { mobj.via.ext.size) == -1) {
return FAIL; return FAIL;

View File

@@ -266,13 +266,12 @@ void ex_align(exarg_T *eap)
} }
for (curwin->w_cursor.lnum = eap->line1; for (curwin->w_cursor.lnum = eap->line1;
curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) { curwin->w_cursor.lnum <= eap->line2; curwin->w_cursor.lnum++) {
if (eap->cmdidx == CMD_left) { // left align if (eap->cmdidx == CMD_left) { // left align
new_indent = indent; new_indent = indent;
} else { } else {
has_tab = false; // avoid uninit warnings has_tab = false; // avoid uninit warnings
len = linelen(eap->cmdidx == CMD_right ? &has_tab len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent();
: NULL) - get_indent();
if (len <= 0) { // skip blank lines if (len <= 0) { // skip blank lines
continue; continue;

View File

@@ -539,9 +539,7 @@ static void discard_exception(except_T *excp, bool was_finished)
if (debug_break_level > 0 || *p_vfile == NUL) { if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = true; // always scroll up, don't overwrite msg_scroll = true; // always scroll up, don't overwrite
} }
smsg(was_finished ? _("Exception finished: %s") smsg(was_finished ? _("Exception finished: %s") : _("Exception discarded: %s"), excp->value);
: _("Exception discarded: %s"),
excp->value);
msg_puts("\n"); // don't overwrite this either msg_puts("\n"); // don't overwrite this either
if (debug_break_level > 0 || *p_vfile == NUL) { if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row; cmdline_row = msg_row;
@@ -1950,7 +1948,7 @@ void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, int *cond_lev
{ {
while (cstack->cs_idx > idx) { while (cstack->cs_idx > idx) {
if (cstack->cs_flags[cstack->cs_idx] & cond_type) { if (cstack->cs_flags[cstack->cs_idx] & cond_type) {
--*cond_level; (*cond_level)--;
} }
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) { if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
free_for_info(cstack->cs_forinfo[cstack->cs_idx]); free_for_info(cstack->cs_forinfo[cstack->cs_idx]);

View File

@@ -308,7 +308,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
goto error_return; goto error_return;
} }
path += 2; path += 2;
} else } else // NOLINT(readability/braces)
#endif #endif
if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) { if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == FAIL) {
goto error_return; goto error_return;
@@ -619,16 +619,15 @@ char_u *vim_findfile(void *search_ctx_arg)
#endif #endif
ff_free_stack_element(stackp); ff_free_stack_element(stackp);
continue; continue;
}
#ifdef FF_VERBOSE #ifdef FF_VERBOSE
else if (p_verbose >= 5) { } else if (p_verbose >= 5) {
verbose_enter_scroll(); verbose_enter_scroll();
smsg("Searching: %s (%s)", smsg("Searching: %s (%s)",
stackp->ffs_fix_path, stackp->ffs_wc_path); stackp->ffs_fix_path, stackp->ffs_wc_path);
msg_puts("\n"); // don't overwrite this either msg_puts("\n"); // don't overwrite this either
verbose_leave_scroll(); verbose_leave_scroll();
}
#endif #endif
}
// check depth // check depth
if (stackp->ffs_level <= 0) { if (stackp->ffs_level <= 0) {

View File

@@ -1048,9 +1048,8 @@ retry:
conv_error = curbuf->b_ml.ml_line_count conv_error = curbuf->b_ml.ml_line_count
- linecnt + 1; - linecnt + 1;
} }
} } else if (illegal_byte == 0) {
// Remember the first linenr with an illegal byte // Remember the first linenr with an illegal byte
else if (illegal_byte == 0) {
illegal_byte = curbuf->b_ml.ml_line_count illegal_byte = curbuf->b_ml.ml_line_count
- linecnt + 1; - linecnt + 1;
} }
@@ -1066,7 +1065,7 @@ retry:
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
|| iconv_fd != (iconv_t)-1 || iconv_fd != (iconv_t)-1
#endif #endif
)) { )) { // NOLINT(whitespace/parens)
while (conv_restlen > 0) { while (conv_restlen > 0) {
*(--ptr) = (char)bad_char_behavior; *(--ptr) = (char)bad_char_behavior;
conv_restlen--; conv_restlen--;
@@ -3039,8 +3038,10 @@ nobackup:
// false. // false.
while ((fd = os_open(wfname, while ((fd = os_open(wfname,
O_WRONLY | O_WRONLY |
(append ? (append
(forceit ? (O_APPEND | O_CREAT) : O_APPEND) ? (forceit
? (O_APPEND | O_CREAT)
: O_APPEND)
: (O_CREAT | O_TRUNC)), : (O_CREAT | O_TRUNC)),
perm < 0 ? 0666 : (perm & 0777))) < 0) { perm < 0 ? 0666 : (perm & 0777))) < 0) {
// A forced write will try to create a new file if the old one // A forced write will try to create a new file if the old one
@@ -3336,7 +3337,7 @@ restore_backup:
} else { } else {
errmsg_allocated = true; errmsg_allocated = true;
SET_ERRMSG(xmalloc(300)); SET_ERRMSG(xmalloc(300));
vim_snprintf(errmsg, 300, vim_snprintf(errmsg, 300, // NOLINT(runtime/printf)
_("E513: write error, conversion failed in line %" PRIdLINENR _("E513: write error, conversion failed in line %" PRIdLINENR
" (make 'fenc' empty to override)"), " (make 'fenc' empty to override)"),
write_info.bw_conv_error_lnum); write_info.bw_conv_error_lnum);
@@ -4258,7 +4259,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
} else { } else {
fnamelen = strlen(fname); fnamelen = strlen(fname);
retval = xmalloc(fnamelen + extlen + 3); retval = xmalloc(fnamelen + extlen + 3);
strcpy(retval, fname); strcpy(retval, fname); // NOLINT(runtime/printf)
} }
// Search backwards until we hit a '/', '\' or ':'. // Search backwards until we hit a '/', '\' or ':'.
@@ -4276,12 +4277,11 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
ptr[BASENAMELEN] = '\0'; ptr[BASENAMELEN] = '\0';
} }
char *s; char *s = ptr + strlen(ptr);
s = ptr + strlen(ptr);
// Append the extension. // Append the extension.
// ext can start with '.' and cannot exceed 3 more characters. // ext can start with '.' and cannot exceed 3 more characters.
strcpy(s, ext); strcpy(s, ext); // NOLINT(runtime/printf)
char *e; char *e;
// Prepend the dot if needed. // Prepend the dot if needed.

View File

@@ -167,7 +167,7 @@ char *ga_concat_strings_sep(const garray_T *gap, const char *sep)
s = xstpcpy(s, strings[i]); s = xstpcpy(s, strings[i]);
s = xstpcpy(s, sep); s = xstpcpy(s, sep);
} }
strcpy(s, strings[nelem - 1]); strcpy(s, strings[nelem - 1]); // NOLINT(runtime/printf)
return ret; return ret;
} }

View File

@@ -1274,9 +1274,8 @@ scripterror:
kFileReadOnly|kFileNonBlocking); kFileReadOnly|kFileNonBlocking);
assert(stdin_dup != NULL); assert(stdin_dup != NULL);
scriptin[0] = stdin_dup; scriptin[0] = stdin_dup;
} else if ((scriptin[0] = } else if ((scriptin[0] = file_open_new(&error, argv[0],
file_open_new(&error, argv[0], kFileReadOnly|kFileNonBlocking, kFileReadOnly|kFileNonBlocking, 0)) == NULL) {
0)) == NULL) {
vim_snprintf((char *)IObuff, IOSIZE, vim_snprintf((char *)IObuff, IOSIZE,
_("Cannot open for reading: \"%s\": %s\n"), _("Cannot open for reading: \"%s\": %s\n"),
argv[0], os_strerror(error)); argv[0], os_strerror(error));

View File

@@ -813,8 +813,7 @@ void curs_columns(win_T *wp, int may_scroll)
if ((wp->w_wrow >= wp->w_height_inner if ((wp->w_wrow >= wp->w_height_inner
|| ((prev_skipcol > 0 || ((prev_skipcol > 0
|| wp->w_wrow + so >= wp->w_height_inner) || wp->w_wrow + so >= wp->w_height_inner)
&& (plines = && (plines = plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1
plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1
>= wp->w_height_inner)) >= wp->w_height_inner))
&& wp->w_height_inner != 0 && wp->w_height_inner != 0
&& wp->w_cursor.lnum == wp->w_topline && wp->w_cursor.lnum == wp->w_topline

View File

@@ -207,7 +207,7 @@ void set_init_1(bool clean_arg)
p = "/tmp"; p = "/tmp";
# endif # endif
mustfree = false; mustfree = false;
} else } else // NOLINT(readability/braces)
#endif #endif
{ {
p = vim_getenv(names[n]); p = vim_getenv(names[n]);
@@ -2042,10 +2042,9 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va
} }
redraw_titles(); redraw_titles();
modified_was_set = value; modified_was_set = value;
}
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
else if ((int *)varp == &p_ssl) { } else if ((int *)varp == &p_ssl) {
if (p_ssl) { if (p_ssl) {
psepc = '/'; psepc = '/';
psepcN = '\\'; psepcN = '\\';
@@ -2060,9 +2059,8 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va
buflist_slash_adjust(); buflist_slash_adjust();
alist_slash_adjust(); alist_slash_adjust();
scriptnames_slash_adjust(); scriptnames_slash_adjust();
}
#endif #endif
else if ((int *)varp == &curwin->w_p_wrap) { } else if ((int *)varp == &curwin->w_p_wrap) {
// If 'wrap' is set, set w_leftcol to zero. // If 'wrap' is set, set w_leftcol to zero.
if (curwin->w_p_wrap) { if (curwin->w_p_wrap) {
curwin->w_leftcol = 0; curwin->w_leftcol = 0;
@@ -2681,7 +2679,7 @@ int findoption_len(const char *const arg, const size_t len)
// letter. There are 26 letters, plus the first "t_" option. // letter. There are 26 letters, plus the first "t_" option.
if (quick_tab[1] == 0) { if (quick_tab[1] == 0) {
p = options[0].fullname; p = options[0].fullname;
for (short int i = 1; (s = options[i].fullname) != NULL; i++) { for (uint16_t i = 1; (s = options[i].fullname) != NULL; i++) {
if (s[0] != p[0]) { if (s[0] != p[0]) {
if (s[0] == 't' && s[1] == '_') { if (s[0] == 't' && s[1] == '_') {
quick_tab[26] = i; quick_tab[26] = i;
@@ -3598,8 +3596,7 @@ void unset_global_local_option(char *name, void *from)
} }
p = &(options[opt_idx]); p = &(options[opt_idx]);
switch ((int)p->indir) switch ((int)p->indir) {
{
// global option with local value: use local value if it's been set // global option with local value: use local value if it's been set
case PV_EP: case PV_EP:
clear_string_option(&buf->b_p_ep); clear_string_option(&buf->b_p_ep);
@@ -4862,7 +4859,7 @@ static void option_value2string(vimoption_T *opp, int opt_flags)
snprintf((char *)NameBuff, snprintf((char *)NameBuff,
sizeof(NameBuff), sizeof(NameBuff),
"%" PRId64, "%" PRId64,
(int64_t)*(long *)varp); (int64_t)(*(long *)varp));
} }
} else { // P_STRING } else { // P_STRING
varp = *(char_u **)(varp); varp = *(char_u **)(varp);

View File

@@ -645,7 +645,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in
#ifndef MSWIN #ifndef MSWIN
|| (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end))) || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end)))
#endif #endif
)) { )) { // NOLINT(whitespace/parens)
e = p; e = p;
} }
len = (size_t)(utfc_ptr2len((char *)path_end)); len = (size_t)(utfc_ptr2len((char *)path_end));
@@ -787,7 +787,7 @@ static int find_previous_pathsep(char_u *path, char_u **psep)
{ {
// skip the current separator // skip the current separator
if (*psep > path && vim_ispathsep(**psep)) { if (*psep > path && vim_ispathsep(**psep)) {
--*psep; (*psep)--;
} }
// find the previous separator // find the previous separator

View File

@@ -220,8 +220,7 @@ bool do_tag(char *tag, int type, int count, int forceit, int verbose)
if (*tag != NUL if (*tag != NUL
&& (type == DT_TAG || type == DT_SELECT || type == DT_JUMP && (type == DT_TAG || type == DT_SELECT || type == DT_JUMP
|| type == DT_LTAG || type == DT_LTAG
|| type == DT_CSCOPE || type == DT_CSCOPE)) {
)) {
if (g_do_tagpreview != 0) { if (g_do_tagpreview != 0) {
if (ptag_entry.tagname != NULL if (ptag_entry.tagname != NULL
&& strcmp(ptag_entry.tagname, tag) == 0) { && strcmp(ptag_entry.tagname, tag) == 0) {

View File

@@ -2583,7 +2583,7 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev
// save index for tabclosed event // save index for tabclosed event
char_u prev_idx[NUMBUFLEN]; char_u prev_idx[NUMBUFLEN];
sprintf((char *)prev_idx, "%i", tabpage_index(prev_curtab)); snprintf((char *)prev_idx, NUMBUFLEN, "%i", tabpage_index(prev_curtab));
// Safety check: Autocommands may have closed the window when jumping // Safety check: Autocommands may have closed the window when jumping
// to the other tab page. // to the other tab page.