mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 9.1.1766: Vim9: some functions do not handle null_string correctly
Problem: Vim9: some Vim9 functions do not handle null_string correctly and may crash Vim (kennypete). Solution: Check for null_string correctly in the searchpair() and substitute() functions (Yegappan Lakshmanan). fixes: #18309 closes: #18311 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
0b7d094d70
commit
afa2a81a88
@@ -3875,6 +3875,26 @@ def Test_searchpair()
|
|||||||
errors = ['E1013: Argument 7: type mismatch, expected number but got string', 'E1210: Number required for argument 7']
|
errors = ['E1013: Argument 7: type mismatch, expected number but got string', 'E1210: Number required for argument 7']
|
||||||
v9.CheckSourceDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", 3, "g")'], errors)
|
v9.CheckSourceDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", 3, "g")'], errors)
|
||||||
v9.CheckSourceDefAndScriptFailure(['searchpairpos("a", "b", "c", "r", "1", 3, "g")'], errors)
|
v9.CheckSourceDefAndScriptFailure(['searchpairpos("a", "b", "c", "r", "1", 3, "g")'], errors)
|
||||||
|
|
||||||
|
# calling searchpair() with null_string arguments
|
||||||
|
lines =<< trim END
|
||||||
|
new
|
||||||
|
setline(1, ['{', '', '}'])
|
||||||
|
|
||||||
|
cursor(1, 1)
|
||||||
|
searchpair('{', '', '}', '', null_string)
|
||||||
|
assert_equal(3, line('.'))
|
||||||
|
|
||||||
|
cursor(1, 1)
|
||||||
|
searchpair('{', '', '}', null_string, null_string)
|
||||||
|
assert_equal(3, line('.'))
|
||||||
|
|
||||||
|
cursor(1, 1)
|
||||||
|
searchpair(null_string, null_string, null_string, null_string, null_string)
|
||||||
|
assert_equal(1, line('.'))
|
||||||
|
bw!
|
||||||
|
END
|
||||||
|
v9.CheckSourceDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_searchpos()
|
def Test_searchpos()
|
||||||
@@ -4538,6 +4558,27 @@ def Test_substitute()
|
|||||||
assert_equal("4", substitute("3", '\d', '\="text" x', 'g'))
|
assert_equal("4", substitute("3", '\d', '\="text" x', 'g'))
|
||||||
END
|
END
|
||||||
v9.CheckSourceDefAndScriptFailure(lines, 'E488: Trailing characters: x')
|
v9.CheckSourceDefAndScriptFailure(lines, 'E488: Trailing characters: x')
|
||||||
|
|
||||||
|
# check for using null_string as argument to substitute()
|
||||||
|
lines =<< trim END
|
||||||
|
assert_equal('Vim', 'Vimp'->substitute('p', '', null_string))
|
||||||
|
assert_equal('Vim', 'Vimp'->substitute('p', null_string, null_string))
|
||||||
|
assert_equal('Vimp', 'Vimp'->substitute(null_string, null_string, null_string))
|
||||||
|
assert_equal('', substitute(null_string, null_string, null_string, null_string))
|
||||||
|
END
|
||||||
|
v9.CheckSourceDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
|
# lambda function calling substitute() with null_string arguments
|
||||||
|
lines =<< trim END
|
||||||
|
const Subst_Fn: func = (a: string, b: string, c: string, d: string): string => {
|
||||||
|
return a->substitute(b, c, d)
|
||||||
|
}
|
||||||
|
assert_equal('Vim', Subst_Fn('Vimp', 'p', '', null_string))
|
||||||
|
assert_equal('Vim', Subst_Fn('Vimp', 'p', null_string, null_string))
|
||||||
|
assert_equal('Vimp', Subst_Fn('Vimp', null_string, null_string, null_string))
|
||||||
|
assert_equal('', Subst_Fn(null_string, null_string, null_string, null_string))
|
||||||
|
END
|
||||||
|
v9.CheckSourceDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_swapinfo()
|
def Test_swapinfo()
|
||||||
|
@@ -724,6 +724,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1766,
|
||||||
/**/
|
/**/
|
||||||
1765,
|
1765,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1199,7 +1199,9 @@ compile_arguments(
|
|||||||
isn_T *isn = ((isn_T *)cctx->ctx_instr.ga_data) + instr_count;
|
isn_T *isn = ((isn_T *)cctx->ctx_instr.ga_data) + instr_count;
|
||||||
|
|
||||||
// {skip} argument of searchpair() can be compiled if not empty
|
// {skip} argument of searchpair() can be compiled if not empty
|
||||||
if (isn->isn_type == ISN_PUSHS && *isn->isn_arg.string != NUL)
|
if (isn->isn_type == ISN_PUSHS
|
||||||
|
&& isn->isn_arg.string != NULL
|
||||||
|
&& *isn->isn_arg.string != NUL)
|
||||||
compile_string(isn, cctx, 0);
|
compile_string(isn, cctx, 0);
|
||||||
}
|
}
|
||||||
else if (special_fn == CA_SUBSTITUTE && *argcount == 3
|
else if (special_fn == CA_SUBSTITUTE && *argcount == 3
|
||||||
@@ -1209,7 +1211,9 @@ compile_arguments(
|
|||||||
|
|
||||||
// {sub} argument of substitute() can be compiled if it starts
|
// {sub} argument of substitute() can be compiled if it starts
|
||||||
// with \=
|
// with \=
|
||||||
if (isn->isn_type == ISN_PUSHS && isn->isn_arg.string[0] == '\\'
|
if (isn->isn_type == ISN_PUSHS
|
||||||
|
&& isn->isn_arg.string != NULL
|
||||||
|
&& isn->isn_arg.string[0] == '\\'
|
||||||
&& isn->isn_arg.string[1] == '=')
|
&& isn->isn_arg.string[1] == '=')
|
||||||
compile_string(isn, cctx, 2);
|
compile_string(isn, cctx, 2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user