aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2022-07-28 00:08:20 +0200
committerGitHub <noreply@github.com>2022-07-28 06:08:20 +0800
commit48608a1f46abfba130faa96d59bdf4b8283fe0ac (patch)
treef1e5b0f74a1ef14418de9c4ba9c790a80731ea69 /src
parente0c433833f638fc5e21b00d298661a5fa7c4b5be (diff)
downloadrneovim-48608a1f46abfba130faa96d59bdf4b8283fe0ac.tar.gz
rneovim-48608a1f46abfba130faa96d59bdf4b8283fe0ac.tar.bz2
rneovim-48608a1f46abfba130faa96d59bdf4b8283fe0ac.zip
refactor: enable -Wconversion warning for regexp files (#19521)
Work on https://github.com/neovim/neovim/issues/567
Diffstat (limited to 'src')
-rwxr-xr-xsrc/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/regexp.c36
-rw-r--r--src/nvim/regexp_bt.c76
-rw-r--r--src/nvim/regexp_nfa.c65
4 files changed, 84 insertions, 94 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 0798432255..0732ac6476 100755
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -159,7 +159,6 @@ list(REMOVE_ITEM NVIM_SOURCES ${to_remove})
# Legacy files that do not yet pass -Wconversion.
set(CONV_SOURCES
lua/treesitter.c
- regexp.c
screen.c
spell.c
spellfile.c
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 2e43e388cd..2b42af5750 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -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) {
len += 50; // get some extra
xfree(reg_tofree);
- reg_tofree = xmalloc(len);
- reg_tofreelen = len;
+ reg_tofree = xmalloc((size_t)len);
+ reg_tofreelen = (unsigned)len;
}
STRCPY(reg_tofree, 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) {
// length = len(newsub) - 1 + len(prev_sub) + 1
prevlen = (int)STRLEN(reg_prev_sub);
- tmpsub = xmalloc(STRLEN(newsub) + prevlen);
+ tmpsub = xmalloc(STRLEN(newsub) + (size_t)prevlen);
// copy prefix
len = (int)(p - newsub); // not including ~
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) {
s = NULL;
} 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)->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");
return 0;
}
- *dst++ = c;
+ *dst++ = (char_u)c;
*dst++ = *src++;
*dst++ = *src++;
} else {
@@ -2195,7 +2195,7 @@ char_u *reg_submatch(int no)
if (round == 2) {
STRCPY(retval + len, s);
}
- len += STRLEN(s);
+ len += (ssize_t)STRLEN(s);
if (round == 2) {
retval[len] = '\n';
}
@@ -2213,7 +2213,7 @@ char_u *reg_submatch(int no)
}
if (retval == NULL) {
- retval = xmalloc(len);
+ retval = xmalloc((size_t)len);
}
}
} else {
@@ -2221,7 +2221,7 @@ char_u *reg_submatch(int no)
if (s == NULL || rsm.sm_match->endp[no] == NULL) {
retval = NULL;
} 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;
char_u *expr = (char_u *)expr_arg;
- regexp_engine = p_re;
+ regexp_engine = (int)p_re;
// Check for prefix "\%#=", that sets the regexp engine
if (STRNCMP(expr, "\\%#=", 4) == 0) {
@@ -2394,8 +2394,8 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags)
if (prog != NULL) {
// Store the info needed to call regcomp() again when the engine turns out
// to be very slow when executing it.
- prog->re_engine = regexp_engine;
- prog->re_flags = re_flags;
+ prog->re_engine = (unsigned)regexp_engine;
+ prog->re_flags = (unsigned)re_flags;
}
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.
if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
&& result == NFA_TOO_EXPENSIVE) {
- int save_p_re = p_re;
- int re_flags = rmp->regprog->re_flags;
+ int save_p_re = (int)p_re;
+ int re_flags = (int)rmp->regprog->re_flags;
char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
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;
- int result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col,
- tm, timed_out);
+ long result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out);
rmp->regprog->re_in_use = false;
// NFA engine aborted because it's very slow, use backtracking engine instead.
if (rmp->regprog->re_engine == AUTOMATIC_ENGINE
&& result == NFA_TOO_EXPENSIVE) {
- int save_p_re = p_re;
- int re_flags = rmp->regprog->re_flags;
+ int save_p_re = (int)p_re;
+ int re_flags = (int)rmp->regprog->re_flags;
char_u *pat = vim_strsave(((nfa_regprog_T *)rmp->regprog)->pattern);
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);
rmp->regprog->re_in_use = true;
- result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col,
- tm, timed_out);
+ result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out);
rmp->regprog->re_in_use = false;
}
diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c
index f82006bede..5bb17e0939 100644
--- a/src/nvim/regexp_bt.c
+++ b/src/nvim/regexp_bt.c
@@ -492,7 +492,7 @@ static void regc(int b)
if (regcode == JUST_CALC_SIZE) {
regsize++;
} else {
- *regcode++ = b;
+ *regcode++ = (char_u)b;
}
}
@@ -1493,7 +1493,7 @@ static char_u *regnode(int op)
if (ret == JUST_CALC_SIZE) {
regsize += 3;
} else {
- *regcode++ = op;
+ *regcode++ = (char_u)op;
*regcode++ = NUL; // Null "next" pointer.
*regcode++ = NUL;
}
@@ -1610,7 +1610,7 @@ static void reginsert(int op, char_u *opnd)
}
place = opnd; // Op node, where operand used to be.
- *place++ = op;
+ *place++ = (char_u)op;
*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++ = op;
+ *place++ = (char_u)op;
*place++ = NUL;
*place++ = NUL;
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++ = op;
+ *place++ = (char_u)op;
*place++ = NUL;
*place++ = NUL;
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]"),
reg_magic == MAGIC_ALL);
}
- if (use_multibytecode(i)) {
+ if (use_multibytecode((int)i)) {
ret = regnode(MULTIBYTECODE);
} else {
ret = regnode(EXACTLY);
@@ -2079,7 +2079,7 @@ static char_u *regatom(int *flagp)
if (i == 0) {
regc(0x0a);
} else {
- regmbc(i);
+ regmbc((int)i);
}
regc(NUL);
*flagp |= HASWIDTH;
@@ -2111,8 +2111,8 @@ static char_u *regatom(int *flagp)
if (ret == JUST_CALC_SIZE) {
regsize += 2;
} else {
- *regcode++ = c;
- *regcode++ = cmp;
+ *regcode++ = (char_u)c;
+ *regcode++ = (char_u)cmp;
}
break;
} else if (c == 'l' || c == 'c' || c == 'v') {
@@ -2123,7 +2123,7 @@ static char_u *regatom(int *flagp)
}
if (c == 'l') {
if (cur) {
- n = curwin->w_cursor.lnum;
+ n = (uint32_t)curwin->w_cursor.lnum;
}
ret = regnode(RE_LNUM);
if (save_prev_at_start) {
@@ -2131,7 +2131,7 @@ static char_u *regatom(int *flagp)
}
} else if (c == 'c') {
if (cur) {
- n = curwin->w_cursor.col;
+ n = (uint32_t)curwin->w_cursor.col;
n++;
}
ret = regnode(RE_COL);
@@ -2139,7 +2139,7 @@ static char_u *regatom(int *flagp)
if (cur) {
colnr_T vcol = 0;
getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &vcol);
- n = ++vcol;
+ n = (uint32_t)(++vcol);
}
ret = regnode(RE_VCOL);
}
@@ -2149,7 +2149,7 @@ static char_u *regatom(int *flagp)
// put the number and the optional
// comparator after the opcode
regcode = re_put_uint32(regcode, n);
- *regcode++ = cmp;
+ *regcode++ = (char_u)cmp;
}
break;
}
@@ -2910,7 +2910,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
}
// 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;
// Second pass: emit code.
@@ -2938,7 +2938,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
r->regflags |= RF_LOOKBH;
}
// 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.
if (OP(regnext(scan)) == END) { // Only one top-level choice.
scan = OPERAND(scan);
@@ -3027,7 +3027,7 @@ static int coll_get_char(void)
regparse--;
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_scan = scan;
- regstack.ga_len += sizeof(regitem_T);
+ regstack.ga_len += (int)sizeof(regitem_T);
return rp;
}
@@ -3519,7 +3519,7 @@ static void regstack_pop(char_u **scan)
rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1;
*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
@@ -3704,7 +3704,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
int mark = OPERAND(scan)[0];
int cmp = OPERAND(scan)[1];
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);
// 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) {
status = RA_FAIL;
} else {
- rp->rs_no = no;
+ rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &rex.reg_startpos[no],
&rex.reg_startp[no]);
// 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) {
status = RA_FAIL;
} else {
- rp->rs_no = no;
+ rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &reg_startzpos[no],
&reg_startzp[no]);
// 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) {
status = RA_FAIL;
} 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]);
// 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) {
status = RA_FAIL;
} else {
- rp->rs_no = no;
+ rp->rs_no = (int16_t)no;
save_se(&rp->rs_un.sesave, &reg_endzpos[no],
&reg_endzp[no]);
// 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) {
status = RA_FAIL;
} else {
- rp->rs_no = no;
+ rp->rs_no = (int16_t)no;
reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan);
// 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) {
status = RA_FAIL;
} else {
- rp->rs_no = no;
+ rp->rs_no = (int16_t)no;
reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan);
// 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;
} else {
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);
if (rp == NULL) {
status = RA_FAIL;
@@ -4485,7 +4485,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (rp == NULL) {
status = RA_FAIL;
} else {
- rp->rs_no = op;
+ rp->rs_no = (int16_t)op;
reg_save(&rp->rs_un.regsave, &backpos);
next = OPERAND(scan);
// 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;
} else {
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);
if (rp == NULL) {
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.
save_subexpr(((regbehind_T *)rp) - 1);
- rp->rs_no = op;
+ rp->rs_no = (int16_t)op;
reg_save(&rp->rs_un.regsave, &backpos);
// First try if what follows matches. If it does then we
// 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:
if (status == RA_NOMATCH) {
regstack_pop(&scan);
- regstack.ga_len -= sizeof(regbehind_T);
+ regstack.ga_len -= (int)sizeof(regbehind_T);
} else {
// The stuff after BEHIND/NOBEHIND matches. Now try if
// 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);
}
regstack_pop(&scan);
- regstack.ga_len -= sizeof(regbehind_T);
+ regstack.ga_len -= (int)sizeof(regbehind_T);
} else {
long limit;
@@ -4806,7 +4806,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
}
}
regstack_pop(&scan);
- regstack.ga_len -= sizeof(regbehind_T);
+ regstack.ga_len -= (int)sizeof(regbehind_T);
}
}
break;
@@ -4817,7 +4817,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (status == RA_MATCH) {
regstack_pop(&scan);
- regstack.ga_len -= sizeof(regstar_T);
+ regstack.ga_len -= (int)sizeof(regstar_T);
break;
}
@@ -4883,7 +4883,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
if (status != RA_CONT) {
// Failed.
regstack_pop(&scan);
- regstack.ga_len -= sizeof(regstar_T);
+ regstack.ga_len -= (int)sizeof(regstar_T);
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].col >= reg_startzpos[i].col) {
re_extmatch_out->matches[i] =
- vim_strnsave(reg_getline(reg_startzpos[i].lnum)
- + reg_startzpos[i].col,
- reg_endzpos[i].col
- - reg_startzpos[i].col);
+ vim_strnsave(reg_getline(reg_startzpos[i].lnum) + reg_startzpos[i].col,
+ (size_t)(reg_endzpos[i].col - reg_startzpos[i].col));
}
} else {
if (reg_startzp[i] != NULL && reg_endzp[i] != NULL) {
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]));
}
}
}
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index eda18ebec9..c1cc877d06 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -545,7 +545,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
return NULL;
}
- ret = xmalloc(len);
+ ret = xmalloc((size_t)len);
p = start->out->out; // skip first char, it goes into regstart
s = ret;
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
// 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));
post_ptr = new_start + (post_ptr - post_start);
post_end = new_start + new_max;
@@ -2079,7 +2079,7 @@ static int nfa_regatom(void)
}
// A NUL is stored in the text as NL
// TODO(vim): what if a composing character follows?
- EMIT(nr == 0 ? 0x0a : nr);
+ EMIT(nr == 0 ? 0x0a : (int)nr);
}
break;
@@ -2646,7 +2646,7 @@ static int nfa_regpiece(void)
EMIT(i);
if (i == NFA_PREV_ATOM_JUST_BEFORE
|| i == NFA_PREV_ATOM_JUST_BEFORE_NEG) {
- EMIT(c2);
+ EMIT((int)c2);
}
break;
@@ -3850,7 +3850,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
if (nfa_calc_size == false) {
// 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;
stack_end = stack + (nstate + 1);
}
@@ -4472,10 +4472,9 @@ static void clear_sub(regsub_T *sub)
{
if (REG_MULTI) {
// Use 0xff to set lnum to -1
- memset(sub->list.multi, 0xff,
- sizeof(struct multipos) * rex.nfa_nsubexpr);
+ memset(sub->list.multi, 0xff, sizeof(struct multipos) * (size_t)rex.nfa_nsubexpr);
} 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;
}
@@ -4489,13 +4488,11 @@ static void copy_sub(regsub_T *to, regsub_T *from)
if (from->in_use > 0) {
// Copy the match start and end positions.
if (REG_MULTI) {
- memmove(&to->list.multi[0],
- &from->list.multi[0],
- sizeof(struct multipos) * from->in_use);
+ memmove(&to->list.multi[0], &from->list.multi[0],
+ sizeof(struct multipos) * (size_t)from->in_use);
} else {
- memmove(&to->list.line[0],
- &from->list.line[0],
- sizeof(struct linepos) * from->in_use);
+ memmove(&to->list.line[0], &from->list.line[0],
+ sizeof(struct linepos) * (size_t)from->in_use);
}
}
}
@@ -4511,13 +4508,11 @@ static void copy_sub_off(regsub_T *to, regsub_T *from)
if (from->in_use > 1) {
// Copy the match start and end positions.
if (REG_MULTI) {
- memmove(&to->list.multi[1],
- &from->list.multi[1],
- sizeof(struct multipos) * (from->in_use - 1));
+ memmove(&to->list.multi[1], &from->list.multi[1],
+ sizeof(struct multipos) * (size_t)(from->in_use - 1));
} else {
- memmove(&to->list.line[1],
- &from->list.line[1],
- sizeof(struct linepos) * (from->in_use - 1));
+ memmove(&to->list.line[1], &from->list.line[1],
+ sizeof(struct linepos) * (size_t)(from->in_use - 1));
}
}
}
@@ -4964,7 +4959,7 @@ skip_add:
// be (a lot) bigger than anticipated.
if (l->n == l->len) {
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) {
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
// and move the states to the right position
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) {
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;
memmove(&(newl[0]),
&(l->t[0]),
- sizeof(nfa_thread_T) * listidx);
+ sizeof(nfa_thread_T) * (size_t)listidx);
memmove(&(newl[listidx]),
&(l->t[l->n - count]),
- sizeof(nfa_thread_T) * count);
+ sizeof(nfa_thread_T) * (size_t)count);
memmove(&(newl[listidx + count]),
&(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);
l->t = newl;
} 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
memmove(&(l->t[listidx + count]),
&(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]),
&(l->t[l->n - 1]),
- sizeof(nfa_thread_T) * count);
+ sizeof(nfa_thread_T) * (size_t)count);
}
}
--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.
if (*listids == NULL || *listids_len < prog->nstate) {
xfree(*listids);
- *listids = xmalloc(sizeof(**listids) * prog->nstate);
+ *listids = xmalloc(sizeof(**listids) * (size_t)prog->nstate);
*listids_len = prog->nstate;
}
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].col = col;
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 {
rex.reg_startp[0] = rex.line + col;
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;
// 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].len = prog->nstate + 1;
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_GT:
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);
// 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) {
re_extmatch_out->matches[i] =
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 {
struct linepos *lpos = &subs.synt.list.line[i];
if (lpos->start != NULL && lpos->end != NULL) {
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);
// 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);
state_ptr = prog->state;
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_icombine = false;
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.