refactor: enable -Wconversion warning for regexp files (#19521)

Work on https://github.com/neovim/neovim/issues/567
This commit is contained in:
dundargoc
2022-07-28 00:08:20 +02:00
committed by GitHub
parent e0c433833f
commit 48608a1f46
4 changed files with 84 additions and 94 deletions

View File

@@ -159,7 +159,6 @@ list(REMOVE_ITEM NVIM_SOURCES ${to_remove})
# Legacy files that do not yet pass -Wconversion. # Legacy files that do not yet pass -Wconversion.
set(CONV_SOURCES set(CONV_SOURCES
lua/treesitter.c lua/treesitter.c
regexp.c
screen.c screen.c
spell.c spell.c
spellfile.c spellfile.c

View File

@@ -1270,8 +1270,8 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e
if (reg_tofree == NULL || len >= (int)reg_tofreelen) { if (reg_tofree == NULL || len >= (int)reg_tofreelen) {
len += 50; // get some extra len += 50; // get some extra
xfree(reg_tofree); xfree(reg_tofree);
reg_tofree = xmalloc(len); reg_tofree = xmalloc((size_t)len);
reg_tofreelen = len; reg_tofreelen = (unsigned)len;
} }
STRCPY(reg_tofree, rex.line); STRCPY(reg_tofree, rex.line);
rex.input = reg_tofree + (rex.input - rex.line); rex.input = reg_tofree + (rex.input - rex.line);
@@ -1554,7 +1554,7 @@ char_u *regtilde(char_u *source, int magic, bool preview)
if (reg_prev_sub != NULL) { if (reg_prev_sub != NULL) {
// length = len(newsub) - 1 + len(prev_sub) + 1 // length = len(newsub) - 1 + len(prev_sub) + 1
prevlen = (int)STRLEN(reg_prev_sub); prevlen = (int)STRLEN(reg_prev_sub);
tmpsub = xmalloc(STRLEN(newsub) + prevlen); tmpsub = xmalloc(STRLEN(newsub) + (size_t)prevlen);
// copy prefix // copy prefix
len = (int)(p - newsub); // not including ~ len = (int)(p - newsub); // not including ~
memmove(tmpsub, newsub, (size_t)len); memmove(tmpsub, newsub, (size_t)len);
@@ -1633,7 +1633,7 @@ static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv, int arg
if (s == NULL || rsm.sm_match->endp[i] == NULL) { if (s == NULL || rsm.sm_match->endp[i] == NULL) {
s = NULL; s = NULL;
} else { } else {
s = vim_strnsave(s, rsm.sm_match->endp[i] - s); s = vim_strnsave(s, (size_t)(rsm.sm_match->endp[i] - s));
} }
TV_LIST_ITEM_TV(li)->v_type = VAR_STRING; TV_LIST_ITEM_TV(li)->v_type = VAR_STRING;
TV_LIST_ITEM_TV(li)->vval.v_string = (char *)s; TV_LIST_ITEM_TV(li)->vval.v_string = (char *)s;
@@ -1920,7 +1920,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int des
iemsg("vim_regsub_both(): not enough space"); iemsg("vim_regsub_both(): not enough space");
return 0; return 0;
} }
*dst++ = c; *dst++ = (char_u)c;
*dst++ = *src++; *dst++ = *src++;
*dst++ = *src++; *dst++ = *src++;
} else { } else {
@@ -2195,7 +2195,7 @@ char_u *reg_submatch(int no)
if (round == 2) { if (round == 2) {
STRCPY(retval + len, s); STRCPY(retval + len, s);
} }
len += STRLEN(s); len += (ssize_t)STRLEN(s);
if (round == 2) { if (round == 2) {
retval[len] = '\n'; retval[len] = '\n';
} }
@@ -2213,7 +2213,7 @@ char_u *reg_submatch(int no)
} }
if (retval == NULL) { if (retval == NULL) {
retval = xmalloc(len); retval = xmalloc((size_t)len);
} }
} }
} else { } else {
@@ -2221,7 +2221,7 @@ char_u *reg_submatch(int no)
if (s == NULL || rsm.sm_match->endp[no] == NULL) { if (s == NULL || rsm.sm_match->endp[no] == NULL) {
retval = NULL; retval = NULL;
} else { } else {
retval = vim_strnsave(s, rsm.sm_match->endp[no] - s); retval = vim_strnsave(s, (size_t)(rsm.sm_match->endp[no] - s));
} }
} }
@@ -2326,7 +2326,7 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags)
regprog_T *prog = NULL; regprog_T *prog = NULL;
char_u *expr = (char_u *)expr_arg; char_u *expr = (char_u *)expr_arg;
regexp_engine = p_re; regexp_engine = (int)p_re;
// Check for prefix "\%#=", that sets the regexp engine // Check for prefix "\%#=", that sets the regexp engine
if (STRNCMP(expr, "\\%#=", 4) == 0) { if (STRNCMP(expr, "\\%#=", 4) == 0) {
@@ -2394,8 +2394,8 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags)
if (prog != NULL) { if (prog != NULL) {
// Store the info needed to call regcomp() again when the engine turns out // Store the info needed to call regcomp() again when the engine turns out
// to be very slow when executing it. // to be very slow when executing it.
prog->re_engine = regexp_engine; prog->re_engine = (unsigned)regexp_engine;
prog->re_flags = re_flags; prog->re_flags = (unsigned)re_flags;
} }
return prog; return prog;
@@ -2473,8 +2473,8 @@ static bool vim_regexec_string(regmatch_T *rmp, char_u *line, colnr_T col, bool
// NFA engine aborted because it's very slow, use backtracking engine instead. // NFA engine aborted because it's very slow, use backtracking engine instead.
if (rmp->regprog->re_engine == AUTOMATIC_ENGINE if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
&& result == NFA_TOO_EXPENSIVE) { && result == NFA_TOO_EXPENSIVE) {
int save_p_re = p_re; int save_p_re = (int)p_re;
int re_flags = rmp->regprog->re_flags; int re_flags = (int)rmp->regprog->re_flags;
char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern); char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
p_re = BACKTRACKING_ENGINE; p_re = BACKTRACKING_ENGINE;
@@ -2558,15 +2558,14 @@ long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum,
} }
rex_in_use = true; rex_in_use = true;
int result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, long result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out);
tm, timed_out);
rmp->regprog->re_in_use = false; rmp->regprog->re_in_use = false;
// NFA engine aborted because it's very slow, use backtracking engine instead. // NFA engine aborted because it's very slow, use backtracking engine instead.
if (rmp->regprog->re_engine == AUTOMATIC_ENGINE if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
&& result == NFA_TOO_EXPENSIVE) { && result == NFA_TOO_EXPENSIVE) {
int save_p_re = p_re; int save_p_re = (int)p_re;
int re_flags = rmp->regprog->re_flags; int re_flags = (int)rmp->regprog->re_flags;
char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern); char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
p_re = BACKTRACKING_ENGINE; p_re = BACKTRACKING_ENGINE;
@@ -2587,8 +2586,7 @@ long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum,
vim_regfree(prev_prog); vim_regfree(prev_prog);
rmp->regprog->re_in_use = true; rmp->regprog->re_in_use = true;
result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out);
tm, timed_out);
rmp->regprog->re_in_use = false; rmp->regprog->re_in_use = false;
} }

View File

@@ -492,7 +492,7 @@ static void regc(int b)
if (regcode == JUST_CALC_SIZE) { if (regcode == JUST_CALC_SIZE) {
regsize++; regsize++;
} else { } else {
*regcode++ = b; *regcode++ = (char_u)b;
} }
} }
@@ -1493,7 +1493,7 @@ static char_u *regnode(int op)
if (ret == JUST_CALC_SIZE) { if (ret == JUST_CALC_SIZE) {
regsize += 3; regsize += 3;
} else { } else {
*regcode++ = op; *regcode++ = (char_u)op;
*regcode++ = NUL; // Null "next" pointer. *regcode++ = NUL; // Null "next" pointer.
*regcode++ = NUL; *regcode++ = NUL;
} }
@@ -1610,7 +1610,7 @@ static void reginsert(int op, char_u *opnd)
} }
place = opnd; // Op node, where operand used to be. place = opnd; // Op node, where operand used to be.
*place++ = op; *place++ = (char_u)op;
*place++ = NUL; *place++ = NUL;
*place = NUL; *place = NUL;
} }
@@ -1637,7 +1637,7 @@ static void reginsert_nr(int op, long val, char_u *opnd)
} }
place = opnd; // Op node, where operand used to be. place = opnd; // Op node, where operand used to be.
*place++ = op; *place++ = (char_u)op;
*place++ = NUL; *place++ = NUL;
*place++ = NUL; *place++ = NUL;
assert(val >= 0 && (uintmax_t)val <= UINT32_MAX); assert(val >= 0 && (uintmax_t)val <= UINT32_MAX);
@@ -1668,7 +1668,7 @@ static void reginsert_limits(int op, long minval, long maxval, char_u *opnd)
} }
place = opnd; // Op node, where operand used to be. place = opnd; // Op node, where operand used to be.
*place++ = op; *place++ = (char_u)op;
*place++ = NUL; *place++ = NUL;
*place++ = NUL; *place++ = NUL;
assert(minval >= 0 && (uintmax_t)minval <= UINT32_MAX); assert(minval >= 0 && (uintmax_t)minval <= UINT32_MAX);
@@ -2071,7 +2071,7 @@ static char_u *regatom(int *flagp)
EMSG2_RET_NULL(_("E678: Invalid character after %s%%[dxouU]"), EMSG2_RET_NULL(_("E678: Invalid character after %s%%[dxouU]"),
reg_magic == MAGIC_ALL); reg_magic == MAGIC_ALL);
} }
if (use_multibytecode(i)) { if (use_multibytecode((int)i)) {
ret = regnode(MULTIBYTECODE); ret = regnode(MULTIBYTECODE);
} else { } else {
ret = regnode(EXACTLY); ret = regnode(EXACTLY);
@@ -2079,7 +2079,7 @@ static char_u *regatom(int *flagp)
if (i == 0) { if (i == 0) {
regc(0x0a); regc(0x0a);
} else { } else {
regmbc(i); regmbc((int)i);
} }
regc(NUL); regc(NUL);
*flagp |= HASWIDTH; *flagp |= HASWIDTH;
@@ -2111,8 +2111,8 @@ static char_u *regatom(int *flagp)
if (ret == JUST_CALC_SIZE) { if (ret == JUST_CALC_SIZE) {
regsize += 2; regsize += 2;
} else { } else {
*regcode++ = c; *regcode++ = (char_u)c;
*regcode++ = cmp; *regcode++ = (char_u)cmp;
} }
break; break;
} else if (c == 'l' || c == 'c' || c == 'v') { } else if (c == 'l' || c == 'c' || c == 'v') {
@@ -2123,7 +2123,7 @@ static char_u *regatom(int *flagp)
} }
if (c == 'l') { if (c == 'l') {
if (cur) { if (cur) {
n = curwin->w_cursor.lnum; n = (uint32_t)curwin->w_cursor.lnum;
} }
ret = regnode(RE_LNUM); ret = regnode(RE_LNUM);
if (save_prev_at_start) { if (save_prev_at_start) {
@@ -2131,7 +2131,7 @@ static char_u *regatom(int *flagp)
} }
} else if (c == 'c') { } else if (c == 'c') {
if (cur) { if (cur) {
n = curwin->w_cursor.col; n = (uint32_t)curwin->w_cursor.col;
n++; n++;
} }
ret = regnode(RE_COL); ret = regnode(RE_COL);
@@ -2139,7 +2139,7 @@ static char_u *regatom(int *flagp)
if (cur) { if (cur) {
colnr_T vcol = 0; colnr_T vcol = 0;
getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol); getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol);
n = ++vcol; n = (uint32_t)(++vcol);
} }
ret = regnode(RE_VCOL); ret = regnode(RE_VCOL);
} }
@@ -2149,7 +2149,7 @@ static char_u *regatom(int *flagp)
// put the number and the optional // put the number and the optional
// comparator after the opcode // comparator after the opcode
regcode = re_put_uint32(regcode, n); regcode = re_put_uint32(regcode, n);
*regcode++ = cmp; *regcode++ = (char_u)cmp;
} }
break; break;
} }
@@ -2910,7 +2910,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
} }
// Allocate space. // Allocate space.
bt_regprog_T *r = xmalloc(sizeof(bt_regprog_T) + regsize); bt_regprog_T *r = xmalloc(sizeof(bt_regprog_T) + (size_t)regsize);
r->re_in_use = false; r->re_in_use = false;
// Second pass: emit code. // Second pass: emit code.
@@ -2938,7 +2938,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
r->regflags |= RF_LOOKBH; r->regflags |= RF_LOOKBH;
} }
// Remember whether this pattern has any \z specials in it. // Remember whether this pattern has any \z specials in it.
r->reghasz = re_has_z; r->reghasz = (char_u)re_has_z;
scan = r->program + 1; // First BRANCH. scan = r->program + 1; // First BRANCH.
if (OP(regnext(scan)) == END) { // Only one top-level choice. if (OP(regnext(scan)) == END) { // Only one top-level choice.
scan = OPERAND(scan); scan = OPERAND(scan);
@@ -3027,7 +3027,7 @@ static int coll_get_char(void)
regparse--; regparse--;
nr = '\\'; nr = '\\';
} }
return nr; return (int)nr;
} }
/* /*
@@ -3505,7 +3505,7 @@ static regitem_T *regstack_push(regstate_T state, char_u *scan)
rp->rs_state = state; rp->rs_state = state;
rp->rs_scan = scan; rp->rs_scan = scan;
regstack.ga_len += sizeof(regitem_T); regstack.ga_len += (int)sizeof(regitem_T);
return rp; return rp;
} }
@@ -3519,7 +3519,7 @@ static void regstack_pop(char_u **scan)
rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1; rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1;
*scan = rp->rs_scan; *scan = rp->rs_scan;
regstack.ga_len -= sizeof(regitem_T); regstack.ga_len -= (int)sizeof(regitem_T);
} }
// Save the current subexpr to "bp", so that they can be restored // Save the current subexpr to "bp", so that they can be restored
@@ -3704,7 +3704,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
int mark = OPERAND(scan)[0]; int mark = OPERAND(scan)[0];
int cmp = OPERAND(scan)[1]; int cmp = OPERAND(scan)[1];
pos_T *pos; pos_T *pos;
size_t col = REG_MULTI ? rex.input - rex.line : 0; size_t col = REG_MULTI ? (size_t)(rex.input - rex.line) : 0;
fmark_T *fm = mark_get(rex.reg_buf, curwin, NULL, kMarkBufLocal, mark); fmark_T *fm = mark_get(rex.reg_buf, curwin, NULL, kMarkBufLocal, mark);
// Line may have been freed, get it again. // Line may have been freed, get it again.
@@ -4168,7 +4168,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &rex.reg_startpos[no], save_se(&rp->rs_un.sesave, &rex.reg_startpos[no],
&rex.reg_startp[no]); &rex.reg_startp[no]);
// We simply continue and handle the result when done. // We simply continue and handle the result when done.
@@ -4198,7 +4198,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &reg_startzpos[no], save_se(&rp->rs_un.sesave, &reg_startzpos[no],
&reg_startzp[no]); &reg_startzp[no]);
// We simply continue and handle the result when done. // We simply continue and handle the result when done.
@@ -4221,7 +4221,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &rex.reg_endpos[no], &rex.reg_endp[no]); save_se(&rp->rs_un.sesave, &rex.reg_endpos[no], &rex.reg_endp[no]);
// We simply continue and handle the result when done. // We simply continue and handle the result when done.
} }
@@ -4242,7 +4242,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &reg_endzpos[no], save_se(&rp->rs_un.sesave, &reg_endzpos[no],
&reg_endzp[no]); &reg_endzp[no]);
// We simply continue and handle the result when done. // We simply continue and handle the result when done.
@@ -4378,7 +4378,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
reg_save(&rp->rs_un.regsave, &backpos); reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan); next = OPERAND(scan);
// We continue and handle the result when done. // We continue and handle the result when done.
@@ -4394,7 +4394,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = no; rp->rs_no = (int16_t)no;
reg_save(&rp->rs_un.regsave, &backpos); reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan); next = OPERAND(scan);
// We continue and handle the result when done. // We continue and handle the result when done.
@@ -4463,7 +4463,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
status = RA_FAIL; status = RA_FAIL;
} else { } else {
ga_grow(&regstack, sizeof(regstar_T)); ga_grow(&regstack, sizeof(regstar_T));
regstack.ga_len += sizeof(regstar_T); regstack.ga_len += (int)sizeof(regstar_T);
rp = regstack_push(rst.minval <= rst.maxval ? RS_STAR_LONG : RS_STAR_SHORT, scan); rp = regstack_push(rst.minval <= rst.maxval ? RS_STAR_LONG : RS_STAR_SHORT, scan);
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
@@ -4485,7 +4485,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
} else { } else {
rp->rs_no = op; rp->rs_no = (int16_t)op;
reg_save(&rp->rs_un.regsave, &backpos); reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan); next = OPERAND(scan);
// We continue and handle the result when done. // We continue and handle the result when done.
@@ -4500,7 +4500,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
status = RA_FAIL; status = RA_FAIL;
} else { } else {
ga_grow(&regstack, sizeof(regbehind_T)); ga_grow(&regstack, sizeof(regbehind_T));
regstack.ga_len += sizeof(regbehind_T); regstack.ga_len += (int)sizeof(regbehind_T);
rp = regstack_push(RS_BEHIND1, scan); rp = regstack_push(RS_BEHIND1, scan);
if (rp == NULL) { if (rp == NULL) {
status = RA_FAIL; status = RA_FAIL;
@@ -4509,7 +4509,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
// when there is a match but we don't use it. // when there is a match but we don't use it.
save_subexpr(((regbehind_T *)rp) - 1); save_subexpr(((regbehind_T *)rp) - 1);
rp->rs_no = op; rp->rs_no = (int16_t)op;
reg_save(&rp->rs_un.regsave, &backpos); reg_save(&rp->rs_un.regsave, &backpos);
// First try if what follows matches. If it does then we // First try if what follows matches. If it does then we
// check the behind match by looping. // check the behind match by looping.
@@ -4689,7 +4689,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
case RS_BEHIND1: case RS_BEHIND1:
if (status == RA_NOMATCH) { if (status == RA_NOMATCH) {
regstack_pop(&scan); regstack_pop(&scan);
regstack.ga_len -= sizeof(regbehind_T); regstack.ga_len -= (int)sizeof(regbehind_T);
} else { } else {
// The stuff after BEHIND/NOBEHIND matches. Now try if // The stuff after BEHIND/NOBEHIND matches. Now try if
// the behind part does (not) match before the current // the behind part does (not) match before the current
@@ -4732,7 +4732,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
restore_subexpr(((regbehind_T *)rp) - 1); restore_subexpr(((regbehind_T *)rp) - 1);
} }
regstack_pop(&scan); regstack_pop(&scan);
regstack.ga_len -= sizeof(regbehind_T); regstack.ga_len -= (int)sizeof(regbehind_T);
} else { } else {
long limit; long limit;
@@ -4806,7 +4806,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
} }
} }
regstack_pop(&scan); regstack_pop(&scan);
regstack.ga_len -= sizeof(regbehind_T); regstack.ga_len -= (int)sizeof(regbehind_T);
} }
} }
break; break;
@@ -4817,7 +4817,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (status == RA_MATCH) { if (status == RA_MATCH) {
regstack_pop(&scan); regstack_pop(&scan);
regstack.ga_len -= sizeof(regstar_T); regstack.ga_len -= (int)sizeof(regstar_T);
break; break;
} }
@@ -4883,7 +4883,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (status != RA_CONT) { if (status != RA_CONT) {
// Failed. // Failed.
regstack_pop(&scan); regstack_pop(&scan);
regstack.ga_len -= sizeof(regstar_T); regstack.ga_len -= (int)sizeof(regstar_T);
status = RA_NOMATCH; status = RA_NOMATCH;
} }
} }
@@ -4974,15 +4974,13 @@ static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_o
&& reg_endzpos[i].lnum == reg_startzpos[i].lnum && reg_endzpos[i].lnum == reg_startzpos[i].lnum
&& reg_endzpos[i].col >= reg_startzpos[i].col) { && reg_endzpos[i].col >= reg_startzpos[i].col) {
re_extmatch_out->matches[i] = re_extmatch_out->matches[i] =
vim_strnsave(reg_getline(reg_startzpos[i].lnum) vim_strnsave(reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col,
+ reg_startzpos[i].col, (size_t)(reg_endzpos[i].col - reg_startzpos[i].col));
reg_endzpos[i].col
- reg_startzpos[i].col);
} }
} else { } else {
if (reg_startzp[i] != NULL && reg_endzp[i] != NULL) { if (reg_startzp[i] != NULL && reg_endzp[i] != NULL) {
re_extmatch_out->matches[i] = re_extmatch_out->matches[i] =
vim_strnsave(reg_startzp[i], reg_endzp[i] - reg_startzp[i]); vim_strnsave(reg_startzp[i], (size_t)(reg_endzp[i] - reg_startzp[i]));
} }
} }
} }

View File

@@ -545,7 +545,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
return NULL; return NULL;
} }
ret = xmalloc(len); ret = xmalloc((size_t)len);
p = start->out->out; // skip first char, it goes into regstart p = start->out->out; // skip first char, it goes into regstart
s = ret; s = ret;
while (p->c > 0) { while (p->c > 0) {
@@ -565,7 +565,7 @@ static void realloc_post_list(void)
{ {
// For weird patterns the number of states can be very high. Increasing by // For weird patterns the number of states can be very high. Increasing by
// 50% seems a reasonable compromise between memory use and speed. // 50% seems a reasonable compromise between memory use and speed.
const size_t new_max = (post_end - post_start) * 3 / 2; const size_t new_max = (size_t)(post_end - post_start) * 3 / 2;
int *new_start = xrealloc(post_start, new_max * sizeof(int)); int *new_start = xrealloc(post_start, new_max * sizeof(int));
post_ptr = new_start + (post_ptr - post_start); post_ptr = new_start + (post_ptr - post_start);
post_end = new_start + new_max; post_end = new_start + new_max;
@@ -2079,7 +2079,7 @@ static int nfa_regatom(void)
} }
// A NUL is stored in the text as NL // A NUL is stored in the text as NL
// TODO(vim): what if a composing character follows? // TODO(vim): what if a composing character follows?
EMIT(nr == 0 ? 0x0a : nr); EMIT(nr == 0 ? 0x0a : (int)nr);
} }
break; break;
@@ -2646,7 +2646,7 @@ static int nfa_regpiece(void)
EMIT(i); EMIT(i);
if (i == NFA_PREV_ATOM_JUST_BEFORE if (i == NFA_PREV_ATOM_JUST_BEFORE
|| i == NFA_PREV_ATOM_JUST_BEFORE_NEG) { || i == NFA_PREV_ATOM_JUST_BEFORE_NEG) {
EMIT(c2); EMIT((int)c2);
} }
break; break;
@@ -3850,7 +3850,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
if (nfa_calc_size == false) { if (nfa_calc_size == false) {
// Allocate space for the stack. Max states on the stack: "nstate". // Allocate space for the stack. Max states on the stack: "nstate".
stack = xmalloc((nstate + 1) * sizeof(Frag_T)); stack = xmalloc((size_t)(nstate + 1) * sizeof(Frag_T));
stackp = stack; stackp = stack;
stack_end = stack + (nstate + 1); stack_end = stack + (nstate + 1);
} }
@@ -4472,10 +4472,9 @@ static void clear_sub(regsub_T *sub)
{ {
if (REG_MULTI) { if (REG_MULTI) {
// Use 0xff to set lnum to -1 // Use 0xff to set lnum to -1
memset(sub->list.multi, 0xff, memset(sub->list.multi, 0xff, sizeof(struct multipos) * (size_t)rex.nfa_nsubexpr);
sizeof(struct multipos) * rex.nfa_nsubexpr);
} else { } else {
memset(sub->list.line, 0, sizeof(struct linepos) * rex.nfa_nsubexpr); memset(sub->list.line, 0, sizeof(struct linepos) * (size_t)rex.nfa_nsubexpr);
} }
sub->in_use = 0; sub->in_use = 0;
} }
@@ -4489,13 +4488,11 @@ static void copy_sub(regsub_T *to, regsub_T *from)
if (from->in_use > 0) { if (from->in_use > 0) {
// Copy the match start and end positions. // Copy the match start and end positions.
if (REG_MULTI) { if (REG_MULTI) {
memmove(&to->list.multi[0], memmove(&to->list.multi[0], &from->list.multi[0],
&from->list.multi[0], sizeof(struct multipos) * (size_t)from->in_use);
sizeof(struct multipos) * from->in_use);
} else { } else {
memmove(&to->list.line[0], memmove(&to->list.line[0], &from->list.line[0],
&from->list.line[0], sizeof(struct linepos) * (size_t)from->in_use);
sizeof(struct linepos) * from->in_use);
} }
} }
} }
@@ -4511,13 +4508,11 @@ static void copy_sub_off(regsub_T *to, regsub_T *from)
if (from->in_use > 1) { if (from->in_use > 1) {
// Copy the match start and end positions. // Copy the match start and end positions.
if (REG_MULTI) { if (REG_MULTI) {
memmove(&to->list.multi[1], memmove(&to->list.multi[1], &from->list.multi[1],
&from->list.multi[1], sizeof(struct multipos) * (size_t)(from->in_use - 1));
sizeof(struct multipos) * (from->in_use - 1));
} else { } else {
memmove(&to->list.line[1], memmove(&to->list.line[1], &from->list.line[1],
&from->list.line[1], sizeof(struct linepos) * (size_t)(from->in_use - 1));
sizeof(struct linepos) * (from->in_use - 1));
} }
} }
} }
@@ -4964,7 +4959,7 @@ skip_add:
// be (a lot) bigger than anticipated. // be (a lot) bigger than anticipated.
if (l->n == l->len) { if (l->n == l->len) {
const int newlen = l->len * 3 / 2 + 50; const int newlen = l->len * 3 / 2 + 50;
const size_t newsize = newlen * sizeof(nfa_thread_T); const size_t newsize = (size_t)newlen * sizeof(nfa_thread_T);
if ((long)(newsize >> 10) >= p_mmp) { if ((long)(newsize >> 10) >= p_mmp) {
emsg(_(e_maxmempat)); emsg(_(e_maxmempat));
@@ -5255,7 +5250,7 @@ static regsubs_T *addstate_here(nfa_list_T *l, nfa_state_T *state, regsubs_T *su
// not enough space to move the new states, reallocate the list // not enough space to move the new states, reallocate the list
// and move the states to the right position // and move the states to the right position
const int newlen = l->len * 3 / 2 + 50; const int newlen = l->len * 3 / 2 + 50;
const size_t newsize = newlen * sizeof(nfa_thread_T); const size_t newsize = (size_t)newlen * sizeof(nfa_thread_T);
if ((long)(newsize >> 10) >= p_mmp) { if ((long)(newsize >> 10) >= p_mmp) {
emsg(_(e_maxmempat)); emsg(_(e_maxmempat));
@@ -5265,13 +5260,13 @@ static regsubs_T *addstate_here(nfa_list_T *l, nfa_state_T *state, regsubs_T *su
l->len = newlen; l->len = newlen;
memmove(&(newl[0]), memmove(&(newl[0]),
&(l->t[0]), &(l->t[0]),
sizeof(nfa_thread_T) * listidx); sizeof(nfa_thread_T) * (size_t)listidx);
memmove(&(newl[listidx]), memmove(&(newl[listidx]),
&(l->t[l->n - count]), &(l->t[l->n - count]),
sizeof(nfa_thread_T) * count); sizeof(nfa_thread_T) * (size_t)count);
memmove(&(newl[listidx + count]), memmove(&(newl[listidx + count]),
&(l->t[listidx + 1]), &(l->t[listidx + 1]),
sizeof(nfa_thread_T) * (l->n - count - listidx - 1)); sizeof(nfa_thread_T) * (size_t)(l->n - count - listidx - 1));
xfree(l->t); xfree(l->t);
l->t = newl; l->t = newl;
} else { } else {
@@ -5279,10 +5274,10 @@ static regsubs_T *addstate_here(nfa_list_T *l, nfa_state_T *state, regsubs_T *su
// end to the current position // end to the current position
memmove(&(l->t[listidx + count]), memmove(&(l->t[listidx + count]),
&(l->t[listidx + 1]), &(l->t[listidx + 1]),
sizeof(nfa_thread_T) * (l->n - listidx - 1)); sizeof(nfa_thread_T) * (size_t)(l->n - listidx - 1));
memmove(&(l->t[listidx]), memmove(&(l->t[listidx]),
&(l->t[l->n - 1]), &(l->t[l->n - 1]),
sizeof(nfa_thread_T) * count); sizeof(nfa_thread_T) * (size_t)count);
} }
} }
--l->n; --l->n;
@@ -5621,7 +5616,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T
// values and clear them. // values and clear them.
if (*listids == NULL || *listids_len < prog->nstate) { if (*listids == NULL || *listids_len < prog->nstate) {
xfree(*listids); xfree(*listids);
*listids = xmalloc(sizeof(**listids) * prog->nstate); *listids = xmalloc(sizeof(**listids) * (size_t)prog->nstate);
*listids_len = prog->nstate; *listids_len = prog->nstate;
} }
nfa_save_listids(prog, *listids); nfa_save_listids(prog, *listids);
@@ -5888,7 +5883,7 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
rex.reg_startpos[0].lnum = rex.lnum; rex.reg_startpos[0].lnum = rex.lnum;
rex.reg_startpos[0].col = col; rex.reg_startpos[0].col = col;
rex.reg_endpos[0].lnum = rex.lnum; rex.reg_endpos[0].lnum = rex.lnum;
rex.reg_endpos[0].col = s2 - rex.line; rex.reg_endpos[0].col = (colnr_T)(s2 - rex.line);
} else { } else {
rex.reg_startp[0] = rex.line + col; rex.reg_startp[0] = rex.line + col;
rex.reg_endp[0] = s2; rex.reg_endp[0] = s2;
@@ -5969,7 +5964,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
nfa_match = false; nfa_match = false;
// Allocate memory for the lists of nodes. // Allocate memory for the lists of nodes.
size_t size = (prog->nstate + 1) * sizeof(nfa_thread_T); size_t size = (size_t)(prog->nstate + 1) * sizeof(nfa_thread_T);
list[0].t = xmalloc(size); list[0].t = xmalloc(size);
list[0].len = prog->nstate + 1; list[0].len = prog->nstate + 1;
list[1].t = xmalloc(size); list[1].t = xmalloc(size);
@@ -6930,7 +6925,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
case NFA_MARK: case NFA_MARK:
case NFA_MARK_GT: case NFA_MARK_GT:
case NFA_MARK_LT: { case NFA_MARK_LT: {
size_t col = REG_MULTI ? rex.input - rex.line : 0; size_t col = REG_MULTI ? (size_t)(rex.input - rex.line) : 0;
fmark_T *fm = mark_get(rex.reg_buf, curwin, NULL, kMarkBufLocal, t->state->val); fmark_T *fm = mark_get(rex.reg_buf, curwin, NULL, kMarkBufLocal, t->state->val);
// Line may have been freed, get it again. // Line may have been freed, get it again.
@@ -7369,14 +7364,14 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *ti
&& mpos->end_col >= mpos->start_col) { && mpos->end_col >= mpos->start_col) {
re_extmatch_out->matches[i] = re_extmatch_out->matches[i] =
vim_strnsave(reg_getline(mpos->start_lnum) + mpos->start_col, vim_strnsave(reg_getline(mpos->start_lnum) + mpos->start_col,
mpos->end_col - mpos->start_col); (size_t)(mpos->end_col - mpos->start_col));
} }
} else { } else {
struct linepos *lpos = &subs.synt.list.line[i]; struct linepos *lpos = &subs.synt.list.line[i];
if (lpos->start != NULL && lpos->end != NULL) { if (lpos->start != NULL && lpos->end != NULL) {
re_extmatch_out->matches[i] = re_extmatch_out->matches[i] =
vim_strnsave(lpos->start, lpos->end - lpos->start); vim_strnsave(lpos->start, (size_t)(lpos->end - lpos->start));
} }
} }
} }
@@ -7567,7 +7562,7 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
post2nfa(postfix, post_ptr, true); post2nfa(postfix, post_ptr, true);
// allocate the regprog with space for the compiled regexp // allocate the regprog with space for the compiled regexp
size_t prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1); size_t prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (size_t)(nstate - 1);
prog = xmalloc(prog_size); prog = xmalloc(prog_size);
state_ptr = prog->state; state_ptr = prog->state;
prog->re_in_use = false; prog->re_in_use = false;
@@ -7651,7 +7646,7 @@ static int nfa_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col, bool line_
rex.reg_ic = rmp->rm_ic; rex.reg_ic = rmp->rm_ic;
rex.reg_icombine = false; rex.reg_icombine = false;
rex.reg_maxcol = 0; rex.reg_maxcol = 0;
return nfa_regexec_both(line, col, NULL, NULL); return (int)nfa_regexec_both(line, col, NULL, NULL);
} }
/// Matches a regexp against multiple lines. /// Matches a regexp against multiple lines.