vim-patch:8.1.0908: can't handle large value for %{nr}v in regexp

Problem:    Can't handle large value for %{nr}v in regexp. (Kuang-che Wu)
Solution:   Give an error if the value is too large. (closes vim/vim#3948)
9403a2168d
This commit is contained in:
Jan Edmund Lazo
2019-07-23 22:54:14 -04:00
parent 9ea449085d
commit 43f4e5d5be

View File

@@ -1503,6 +1503,8 @@ static int nfa_regatom(void)
c = getchr(); c = getchr();
} }
if (c == 'l' || c == 'c' || c == 'v') { if (c == 'l' || c == 'c' || c == 'v') {
int limit = INT_MAX;
if (c == 'l') { if (c == 'l') {
// \%{n}l \%{n}<l \%{n}>l // \%{n}l \%{n}<l \%{n}>l
EMIT(cmp == '<' ? NFA_LNUM_LT : EMIT(cmp == '<' ? NFA_LNUM_LT :
@@ -1518,13 +1520,12 @@ static int nfa_regatom(void)
// \%{n}v \%{n}<v \%{n}>v // \%{n}v \%{n}<v \%{n}>v
EMIT(cmp == '<' ? NFA_VCOL_LT : EMIT(cmp == '<' ? NFA_VCOL_LT :
cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
limit = INT_MAX / MB_MAXBYTES;
} }
#if SIZEOF_INT < SIZEOF_LONG if (n >= limit) {
if (n > INT_MAX) {
EMSG(_("E951: \\% value too large")); EMSG(_("E951: \\% value too large"));
return FAIL; return FAIL;
} }
#endif
EMIT((int)n); EMIT((int)n);
break; break;
} else if (c == '\'' && n == 0) { } else if (c == '\'' && n == 0) {